@andersaloof/sub-array
v1.0.1
Published
Returns a subset of an array, from index + X items before/after the current index, wrapping around if range exceeds the bounds of the array.
Downloads
5
Readme
subArray
Returns a subset of an array, from index + X items before/after the current index, wrapping around if range exceeds the bounds of the array.
Install
$ npm install @andersaloof/sub-array
Why?
Useful when making an "endless" slideshow, as you will get X items in both directions from your current index, wrapping around.
Usage
subArray(items, max, range)
Example code
const subArray = require('@andersaloof/sub-array');
const subset = subArray(['a', 'b', 'c', 'd', 'e'], 2, 1); // Returns the new array ['b', 'c', 'd']
License
MIT