array-range
creates a new array with given range. Study from mattdesl/array-range
Tiny module to create a new dense array with the specified range.
var range = // -> [ 0, 1, 2 ] // -> [ 1, 2, 3 ]
Mainly useful for functional programming. ES6 examples:
var array = // -> [ 0, 1, 4, 9, 16 ] // -> [ 2, 4, 6, 8 ]
It can also be useful for creating a fixed size dense array. Cleaner than apply
and does not create an intermediate array:
//vs. Array
Usage
array(start, end)
Creates a new dense array with a length of end-start
elements. start
is inclusive, end
is exclusive. Negative values also work, e.g. range(-10, 10)
array(len)
Creates a new dense array with len
number of elements, from zero to len-1
.
If len
is unspecified, it defaults to zero (empty array).
License
MIT, see LICENSE.md for details.