An ES5 spec-compliant Array.prototype.reduce
shim/polyfill/replacement that works as far down as ES3.
This package implements the es-shim API interface. It works in an ES3-supported environment and complies with the spec.
Because Array.prototype.reduce
depends on a receiver (the “this” value), the main export takes the array to operate on as the first argument.
Example
var reduce = ;var assert = ; assert;assert;
var reduce = ;var assert = ;/* when Array#reduce is not present */delete Arrayprototypereduce;var shimmed = reduce;assert;var arr = 1 2 3;var { return a + b; };assert;assert;assert;
var reduce = ;var assert = ;/* when Array#reduce is present */var shimmed = reduce;assert;assert;
Tests
Simply clone the repo, npm install
, and run npm test