JSPM

map-reverse

1.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 7315
  • Score
    100M100P100Q129005F
  • License MIT

Apply a function to an array from then end to the beginning.

Package Exports

  • map-reverse

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (map-reverse) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

map-reverse

Build Status

Apply a function to an array from then end to the beginning.

It's may be useful when iterating an array and deleting its elements at the same time.

Install

npm install map-reverse

Usage

Reverse iteration allows you to delete current element from an array when iterating.

var mapReverse = require('map-reverse');

var a = [1, 2, 3, 4, 5, 6, 7];

var b = mapReverse(a, function (item, index) {
    if (item % 2)
        a.splice(index, 1);

    return item;
});

console.log(a);
//[ 2, 4, 6 ]

console.log(b);
//[ 7, 6, 5, 4, 3, 2, 1 ]