1.1.5 • Published 4 years ago

@dima-f1/range-array v1.1.5

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

Travis (.org) Coveralls github npm bundle size (scoped) npm (scoped) NPM

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-array

Yarn:

$ yarn add @dima-f1/range-array

API 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.

ParamTypeDefaultDescription
startnumber1The value from which will be started range of array entries.
endnumber 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
stepnumber1The 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
callbackFnfunction 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']

License

MIT

1.1.5

4 years ago

1.1.4

4 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago