small fixes and additions to examples, added deepFilter to list

This commit is contained in:
hydrabolt
2015-08-12 16:35:17 +01:00
parent 0013891764
commit 3e4f0fb74c
6 changed files with 96 additions and 43 deletions

View File

@@ -72,3 +72,31 @@ exports.List.prototype.filter = function( key, value, onlyOne ) {
return results;
}
exports.List.prototype.deepFilter = function( keys, value, onlyOne ) {
var results = [];
for ( index in this.contents ) {
var child = this.contents[ index ];
var buffer = child;
for(key of keys){
buffer = buffer[key];
}
if ( buffer == value ) {
if ( onlyOne ) {
return child;
} else {
results.push( child );
}
}
}
if ( onlyOne ) {
return false;
}
return results;
}