UNPKG

extendscript-es5-shim

Version:
40 lines (36 loc) 1.06 kB
/* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/ReduceRight */ // Production steps of ECMA-262, Edition 5, 15.4.4.22 // Reference: http://es5.github.io/#x15.4.4.22 if (!Array.prototype.reduceRight) { Array.prototype.reduceRight = function(callback, initialValue) { if (this === void 0 || this === null) { throw new TypeError('Array.prototype.reduceRight called on null or undefined'); } if (callback.__class__ !== 'Function') { throw new TypeError(callback + ' is not a function'); } var t = Object(this), len = t.length >>> 0, k = len - 1, value; if (arguments.length > 1) { value = initialValue; } else { while (k >= 0 && !(k in t)) { k--; } if (k < 0) { throw new TypeError('Reduce of empty array with no initial value'); } value = t[k--]; } for (; k >= 0; k--) { if (k in t) { value = callback(value, t[k], k, t); } } return value; }; }