arraynge
Various transforms for ranges of array/list indices.
Usage
see test/usage.js
API
Import it
var arraynge = ;
Create arraynges
range = ;range = ; // range includes both valuesrange = ; makeRangeFromList = arrayngewithThisList;range = ; listmakeRange = arrayngewithThisList;range = list;
Configure an arraynge
The config functions return the arraynge they were called on, so you can chain them.
range;range;range;range; // forget current listrange; // set new listrange; // set list to object { length: someNumber }
Query the config
range; // -> (string) descriptionrange; // -> (array) [from, upto]range; // -> (any) fromrange; // -> (any) uptorange; // -> (object | false) listrange; // -> (number) list.length or 0
Modify the bounds
Parameter max
or len
is optional. If provided, it should be a number.
(Maximum valid integer index for your list, or the list's length.)
If not provided or undefined
, it is calculated from .len()
.
range; // index === true? set to max.range; // index negative? += len. still neg? set to false.range; // warp indices into range [0 <= x < len]range; // index negative? set to 0. too large? set to max. range; // negative or too large? set to false. range; // add same offset to bothrange; // add offsets to each
Cautious transforms
- They won't modify the config.
- If any of the bounds is not a finite number, or is out of range,
the cautious transforms will abort without any action or
side effect and will return
false
. - Parameters
len
ormax
optional as above.
range; // array [from, upto]range; // array of numbers {from <= x <= upto}, step size = 1range; // numbers like .enumerate but collect iter(list[x], x)
License
ISC