Javascript Array reduceRight(iteratee, initialValue)
Array.prototype.reduceRight = function(iteratee, initialValue) { if (typeof iteratee !== "function") { throw new TypeError(iteratee + ' is not a function') } let arr = this;// w ww. j av a 2 s . co m let result; let index; if (initialValue != void 0) { result = initialValue; index = arr.length - 1; } else { result = arr[arr.length - 1]; index = arr.length - 2; } for (let i = index; i >= 0; i--) { result = iteratee(result, arr[i]); } return result; }