Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

array.prototype.reduce

es-shims20.5mMIT1.0.7

An ES5 spec-compliant Array.prototype.reduce shim/polyfill/replacement that works as far down as ES3.

Array.prototype.reduce, reduce, array, ES5, shim, polyfill, es-shim API

readme

array.prototype.reduce Version Badge

github actions coverage dependency status dev dependency status License Downloads

npm badge

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 = require('array.prototype.reduce');
var assert = require('assert');

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

Tests

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

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

v1.0.7 - 2024-03-20

Commits

  • [Deps] update call-bind, define-properties, es-abstract 4c68200
  • [actions] use reusable workflows f755af3
  • [Refactor] use es-object-atoms where possible d64f55f
  • [Dev Deps] update aud, npmignore, tape 2da232a
  • [Robustness] use es-errors 020b529

v1.0.6 - 2023-08-29

Commits

  • [Deps] update define-properties, es-abstract 5afbf91
  • [Dev Deps] update @es-shims/api, @ljharb/eslint-config, aud, tape abc82a9

v1.0.5 - 2022-11-03

Commits

  • [meta] use npmignore to autogenerate an npmignore file a2333c6
  • [Deps] update es-abstract 86a838f
  • [actions] update rebase action to use reusable workflow 4710394
  • [Dev Deps] update aud, tape e2bcb57
  • [Deps] update define-properties, es-abstract 4c693aa
  • [Deps] update es-abstract ca5557c
  • [Dev Deps] update functions-have-names dcb2d35

v1.0.4 - 2022-04-11

Commits

  • [actions] reuse common workflows 42fe1e2
  • [Fix] properly handle a large negative length b24d3c4
  • [Fix] properly handle only-holes array 823a890
  • [Dev Deps] update eslint, @ljharb/eslint-config, @es-shims/api, safe-publish-latest, tape 235ae27
  • [Dev Deps] update eslint, @ljharb/eslint-config, aud, auto-changelog, tape 7f720c6
  • [actions] update codecov uploader 9d6eff0
  • [Deps] update es-abstract c14d421
  • [Deps] update es-abstract 5288168

v1.0.3 - 2021-10-01

Commits

  • [actions] use node/install instead of node/run; use codecov action bbd7913
  • [Deps] update es-abstract 6f05f53
  • [readme] remove travis badge fc5c01c
  • [Dev Deps] update eslint, @ljharb/eslint-config, @es-shims/api, aud, auto-changelog, tape 7eb4251
  • [Dev Deps] update eslint, @ljharb/eslint-config, aud, functions-have-names, has-strict-mode, tape b6d02ba
  • [actions] update workflows 403b142
  • [readme] add github actions/codecov badges e070a24
  • [actions] update workflows 9657169
  • [Dep] move is-string to prod deps 1eb89d6
  • [Dev Deps] update eslint, tape 70049c6
  • [Deps] update call-bind, es-abstract e49aea9
  • [meta] use prepublishOnly script for npm 7+ e2bbb8b
  • [Tests] increase coverage 4b9b02c
  • [Deps] update es-abstract e349e01

v1.0.2 - 2020-11-19

Commits

  • [Tests] migrate tests to Github Actions 397cded
  • [meta] do not publish github action workflow files 7ac0e80
  • [Deps] update es-abstract; use call-bind where applicable; remove function-bind 3470ed1
  • [Tests] run nyc on all tests 6efa838
  • [Dev Deps] update eslint, @ljharb/eslint-config, aud, auto-changelog, tape eae319e
  • [actions] add "Allow Edits" workflow 87ed4f8
  • [Tests] add implementation test; run es-shim-api in postlint; use tape runner 9bfea52
  • [Dev Deps] update @ljharb/eslint-config, tape, has-strict-mode, functions-have-names fdac028
  • [Dev Deps] update auto-changelog, tape f595f6a
  • [Dev Deps] update auto-changelog; add aud 9d3d84c
  • [actions] switch Automatic Rebase workflow to pull_request_target event 2c05596
  • [Tests] only audit prod deps 89c3610
  • [Deps] update es-abstract 65bdd68
  • [Deps] update es-abstract ad19dd9
  • [Dev Deps] update eslint ce28412

v1.0.1 - 2019-12-20

Commits

  • [Tests] use shared travis-ci configs cc10c0e
  • [Refactor] use split-up es-abstract (77% bundle size decrease) 1d34e2b
  • [meta] update auto-changelog 0d4c1a7
  • [actions] add automatic rebasing / merge commit blocking 3c5a9aa
  • [Dev Deps] update eslint, @ljharb/eslint-config, is-string, tape 37b79b1
  • [Dev Deps] update eslint, @ljharb/eslint-config, safe-publish-latest, functions-have-names f5c5499
  • [Deps] update es-abstract bd187af
  • [meta] add funding field 8992db6
  • [Deps] update es-abstract eda5044

v1.0.0 - 2019-09-30

Commits