Here you can find the source of reduce()
Array.prototype.reduce = function() { return this.length > 1 ? this : this[0]; };
var testArray1 = [1, 3, 5, 4, 2], sumArray = []; Array.prototype.reduce = function() { var sum = 0; for (i=0;i<this.length; ++i) { sum += this[i]; return sumArray.push(sum); }; ...
Array.prototype.reduce = function(aggregate, initial) { const len = this.length; let startIndex = 0; if(typeof initial === 'undefined') { initial = this[0]; startIndex = 1; for(let i = startIndex; i < len; i += 1) { initial = aggregate(initial, this[i], i, this); ...
Array.prototype.reduce = function(callback, initial){ initial = initial || 0; for (var i=0; i< this.length; i++) { initial = callback(initial, this[i], i, this); return initial; wat = [1,2, 3, 4] console.log(wat); ...
Array.prototype.reduce = function(callback, initialValue) { var last, returned; this.forEach(function(item, index, array) { if (index == 0 && initialValue) { returned = initialValue; } else if (index == 1 && !initialValue) { returned = item; } else { last = returned, returned = null; ...