Skip to content
An ES5 spec-compliant `Array.prototype.reduceRight` shim/polyfill/replacement that works as far down as ES3.
JavaScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
test
.eslintrc
.gitignore
.npmrc
.travis.yml
CHANGELOG.md
LICENSE
README.md
auto.js
implementation.js
index.js
package.json
polyfill.js
shim.js

README.md

array.prototype.reduceRight Version Badge

Build Status dependency status dev dependency status License Downloads

npm badge

An ES5 spec-compliant Array.prototype.reduceRight 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.reduceRight depends on a receiver (the “this” value), the main export takes the array to operate on as the first argument.

Example

var reduceRight = require('array.prototype.reduceright');
var assert = require('assert');

assert.equal(reduceRight([1, 2, 3], function (prev, x) { return prev + x; }), 6);
assert.equal(reduceRight([1, 2, 3], function (prev, x) { return prev + x; }, 1), 7);
var reduceRight = require('array.prototype.reduceright');
var assert = require('assert');
/* when Array#reduceRight is not present */
delete Array.prototype.reduceRight;
var shimmed = reduceRight.shim();
assert.equal(shimmed, reduceRight.getPolyfill());
var arr = [1, 2, 3];
var sum = function (a, b) { return a + b; };
assert.equal(arr.reduceRight(sum), reduceRight(arr, sum));
assert.equal(arr.reduceRight(sum), 6);
assert.equal(arr.reduceRight(sum, 1), 7);
var reduceRight = require('array.prototype.reduceright');
var assert = require('assert');
/* when Array#reduceRight is present */
var shimmed = reduceRight.shim();
assert.equal(shimmed, Array.prototype.reduceRight);
assert.equal(arr.reduceRight(sum), reduceRight(arr, sum));

Tests

Simply clone the repo, npm install, and run npm test

You can’t perform that action at this time.