💾arr.max()
💾 replit: arr.max()
Array.prototype.max = function() {
return this.reduce((partialMax, nextValue) => Math.max(partialMax, nextValue));
};
💈範例:
[1,2,3].max(), // 3
[4,2,3].max(), // 4
// [].max(), // ⛔ TypeError: Reduce of empty array with no initial value
Last updated
Was this helpful?