UNPKG

typescript-algorithms-and-datastructures

Version:
57 lines 1.84 kB
(function (factory) { if (typeof module === "object" && typeof module.exports === "object") { var v = factory(require, exports); if (v !== undefined) module.exports = v; } else if (typeof define === "function" && define.amd) { define(["require", "exports"], factory); } })(function (require, exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); class Utils { static range(start, end, step = 1) { let i = start; let output = []; while (i < end) { output.push(i); i = i + step; } return output; } static swapValues(array, from, to) { let temp = array[from]; array[from] = array[to]; array[to] = temp; } static lt(a, b) { return a < b; } static gt(a, b) { return a > b; } static minIndex(array, from = 0, to = array.length, comparator = Utils.gt) { const arraySize = to; let lowestIndex = from; for (let i = from; i < arraySize; i++) { if (comparator(array[lowestIndex], array[i])) { lowestIndex = i; } } return lowestIndex; } static findIndexBy(array, comparator) { let lowestIndex = -1; array.some((entry, index) => { if (comparator(entry, index, array)) { lowestIndex = index; return true; } return false; }); return lowestIndex; } } exports.Utils = Utils; }); //# sourceMappingURL=Utils.js.map