UNPKG

@prelude/array

Version:

Array module.

18 lines 579 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /** * 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]; }; exports.default = modulo; //# sourceMappingURL=modulo.js.map