mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-12 01:23:31 +01:00
small fixes and additions to examples, added deepFilter to list
This commit is contained in:
28
lib/list.js
28
lib/list.js
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user