@dima-f1/range-array
v1.1.5
Published
Create an array with configurable range and optional callback invocation on each entry
Maintainers
Readme
Range-array
With this function you can create an array with configurable range and optional callback invocation on each entry.
Note: This package created for my purposes, and I don't plan to actively maintain it. You can make a fork from this repository and do anything you want.
Table of Contents
Installation
NPM:
$ npm i @dima-f1/range-arrayYarn:
$ yarn add @dima-f1/range-arrayAPI Reference
@dima-f1/range-array~rangeArray([start], end, [step], [callbackFn]) ⇒ array
Create an array with configurable range and optional callback invocation on each entry.
Returns: array - The array that corresponds with given params.
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| [start] | number | 1 | The value from which will be started range of array entries. |
| end | number | | The value at which will be ended range of array entries. If the value of end param is undefined then rangeArray returns an empty array |
| [step] | number | 1 | The value, which will be used to determine the gap between adjacent array entries. If the value of step param is less than 0 then rangeArray returns an empty array |
| [callbackFn] | function | | A function that accepts only one argument - the next range item. If callbackFn function provided then rangeArray calls it one time for each element in the array. |
Usage
import rangeArray from '@dima-f1/range-array';
rangeArray(1, 10);
// => [1,2,3,4,5,6,7,8,9,10]
rangeArray(1, 10, 3);
// => [1,4,7,10]
rangeArray(1, 10, 2, (entry) => `Hello ${entry}`);
// => ['Hello 1','Hello 3','Hello 5','Hello 7','Hello 9']