Wire arrays into the prototype chain (Array.prototype → Object.prototype), add the Array global with isArray(), and implement callback-based methods (map, forEach, filter, find, findIndex, some, every, reduce, reduceRight, sort) plus simple methods (includes, lastIndexOf, reverse, shift, unshift). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
13 lines
435 B
JavaScript
13 lines
435 B
JavaScript
console.log([1, 2, 3, 4].reduce(function(a, b) { return a + b; }));
|
|
console.log([1, 2, 3].reduce(function(a, b) { return a + b; }, 10));
|
|
console.log([42].reduce(function(a, b) { return a + b; }));
|
|
console.log([].reduce(function(a, b) { return a + b; }, 0));
|
|
|
|
console.log([1, 2, 3].reduceRight(function(a, b) { return a + ',' + b; }));
|
|
|
|
try {
|
|
[].reduce(function(a, b) { return a + b; });
|
|
} catch (e) {
|
|
console.log(e.message);
|
|
}
|