UNPKG

raptor-polyfill

Version:

Polyfills for various EcmaScript 5 and EcmaScript 6 methods distributed as CommonJS modules that can be require'd individually or as a whole.

46 lines (39 loc) 1.45 kB
// ES5 15.4.4.22 // http://es5.github.com/#x15.4.4.22 // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/reduceRight if (!Array.prototype.reduceRight) { var toObject = require('./_toObject'); Array.prototype.reduceRight = function reduceRight(fun /*, initial*/) { var self = toObject(this), length = self.length >>> 0; // If no callback function or if callback is not a callable function if (typeof fun !== "function") { throw new TypeError(); } // no value to return if no initial value, empty array if (!length && arguments.length == 1) { throw new TypeError('reduceRight of empty array with no initial value'); } var result, i = length - 1; if (arguments.length >= 2) { result = arguments[1]; } else { do { if (i in self) { result = self[i--]; break; } // if array contains no values, no initial value to return if (--i < 0) { throw new TypeError('reduceRight of empty array with no initial value'); } } while (true); } do { if (i in this) { result = fun.call(void 0, result, self[i], i, self); } } while (i--); return result; }; }