UNPKG

@extra-array/index-range

Version:

Gets index range of part of array.

11 lines (10 loc) 264 B
'use strict'; function index(x, i = 0) { return i < 0 ? Math.max(x.length + i, 0) : Math.min(i, x.length); } function indexRange(x, i = 0, I = x.length) { i = index(x, i); I = Math.max(i, index(x, I)); return [i, I]; } module.exports = indexRange;