0.1.0 • Published 6 years ago

array-map-slice v0.1.0

Weekly downloads
13
License
MIT
Repository
github
Last release
6 years ago

array-map-slice Build Status

Allows to map a slice of the array for each item in the array.

Usage

const mapSlice = require('array-map-slice');

mapSlice([ 1, 2, 3 ], (slice, index, array) => {
    return slice.join('-');
});
// => [ '1', '1-2', '1-2-3' ]

Or if you want to create slices from the right use mapSliceRight:

const mapSlice = require('array-map-slice');

mapSlice.mapSliceRight([ 1, 2, 3 ], (slice, index, array) => {
    return slice.join('-');
});
// => [ '1-2-3', '2-3', '3' ]

Installation

npm install array-map-slice

API

mapSlice(input, mapper) / mapSliceRight(input, mapper)

Returns a new array with values returned by the mapper function.

input

Type: Array

Iterated over in the mapper function which gets splices of it.

mapper (slice, index, array)

Type: Function

Executed for every slice and expected to return the new value.

License

MIT © Florian Goße