Skip to content

indexRange

Subhajit Sahu edited this page May 3, 2023 · 18 revisions

Get zero-based index range for part of array.

Similar: index, indexRange, size, isEmpty.


function indexRange(x, i, I)
// x: an array
// i: begin ±index [0]
// I: end ±index (exclusive) [|x|]
const xarray = require('extra-array');

var x = [2, 4, 6, 8];
xarray.indexRange(x, 1);
// → [ 1, 4 ]

xarray.indexRange(x, 1, -1);
// → [ 1, 3 ]

xarray.indexRange(x, 1, -10);
// → [ 1, 1 ]


References

Clone this wiki locally