UNPKG

@prelude/array

Version:

Array module.

16 lines 499 B
/** * Like `at` but wraps using modulo on length. * @throws {TypeError} if array is empty or index is not a safe integer. */ const modulo = (values, index) => { if (!Number.isSafeInteger(index)) { throw new TypeError(`Expected safe integer index, got ${index}.`); } const n = values.length; if (n === 0) { throw new TypeError('Expected non empty array.'); } return values[((index % n) + n) % n]; }; export default modulo; //# sourceMappingURL=modulo.js.map