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>
9 lines
338 B
JavaScript
9 lines
338 B
JavaScript
console.log([3, 1, 2].sort().join(','));
|
|
console.log([3, 1, 2].sort(function(a, b) { return a - b; }).join(','));
|
|
console.log([1, 3, 2].sort(function(a, b) { return b - a; }).join(','));
|
|
console.log(['banana', 'apple', 'cherry'].sort().join(','));
|
|
console.log([].sort().length);
|
|
var a = [3, 1, 2];
|
|
var b = a.sort();
|
|
console.log(a === b);
|