mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-19 13:03:31 +01:00
Add Collection.reduce
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -210,6 +210,19 @@ class Collection extends Map {
|
|||||||
}
|
}
|
||||||
return true;
|
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;
|
module.exports = Collection;
|
||||||
|
|||||||
Reference in New Issue
Block a user