UNPKG

lgrthms

Version:

Algorithms and data structures for your JavaScript and TypeScript projects 🧑‍💻

13 lines (12 loc) 388 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.swap = void 0; function swap(array, i, j) { if (i < 0 || j < 0 || i > array.length - 1 || j > array.length - 1) { throw new Error('Cannot swap values in array, indexes are out of bounds'); } const temp = array[i]; array[i] = array[j]; array[j] = temp; } exports.swap = swap;