Last active
August 29, 2015 14:18
-
-
Save oxpa/b1091e0f2baf06b46269 to your computer and use it in GitHub Desktop.
some js additions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Array.prototype.update = function(list) { | |
if (list instanceof Array) { | |
for (n of list) { | |
var updated = false; | |
for(var i=0; i< this.length; i++) { | |
if (n.name == this[i].name) {this[i] = n; updated = true; break;} | |
}; | |
if (!updated) this.push(n); | |
} | |
return this; | |
} | |
}; | |
Array.prototype.by_name = function(attr, val) { | |
var rv = Array(); | |
if (attr && val) { | |
for (e of this){ | |
if ( attr in e && e[attr]==val ) { | |
rv.push(e); | |
} | |
} | |
} | |
return rv; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment