UNPKG

@prelude/array

Version:

Array module.

13 lines 469 B
/** 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; }; export default swap; //# sourceMappingURL=swap.js.map