UNPKG

@prelude/array

Version:

Array module.

15 lines 549 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /** In-place swap elements at index `i` and `j`. */ const swap = (values, i, j) => { if (i < 0 || i >= values.length) { throw new TypeError(`Out of bounds index ${i}, length ${values.length}.`); } if (j < 0 || j >= values.length) { throw new TypeError(`Out of bounds index ${i}, length ${values.length}.`); } [values[j], values[i]] = [values[i], values[j]]; return values; }; exports.default = swap; //# sourceMappingURL=swap.js.map