mirror of
https://github.com/danbulant/discord.js
synced 2026-05-26 05:22:15 +00:00
Add Collection.reduce
This commit is contained in:
parent
0bd00b12b7
commit
84b33f9b66
2 changed files with 14 additions and 1 deletions
File diff suppressed because one or more lines are too long
|
|
@ -210,6 +210,19 @@ class Collection extends Map {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Identical to
|
||||
* [Array.reduce()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce).
|
||||
* @param {function} fn Function used to reduce
|
||||
* @param {*} [startVal] The starting value
|
||||
* @returns {*}
|
||||
*/
|
||||
reduce(fn, startVal) {
|
||||
let currentVal = startVal;
|
||||
for (const [key, val] of this) currentVal = fn(currentVal, val, key, this);
|
||||
return currentVal;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Collection;
|
||||
|
|
|
|||
Loading…
Reference in a new issue