This commit is contained in:
minjaesong
2021-06-19 17:17:18 +09:00
parent 94eebd816b
commit 4eed34fa62
2 changed files with 55 additions and 10 deletions

View File

@@ -353,6 +353,12 @@ Array.prototype.shuffle = function() {
return this;
}
Array.prototype.sum = function(selector) {
return this.reduce((acc,val) => acc + ((selector === undefined) ? val : selector(val)), 0)
}
Array.prototype.max = function(selector) {
return this.reduce((acc,val) => (((selector === undefined) ? val : selector(val)) > acc) ? ((selector === undefined) ? val : selector(val)) : acc, 0)
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// NOTE TO PROGRAMMERS: this JS_INIT script does not, and must not be invoked with strict mode //