UNPKG

@graffy/common

Version:

Common libraries that used by various Graffy modules.

47 lines (38 loc) 1.03 kB
"use strict"; exports.__esModule = true; exports.default = find; function find(items, compare, first, last) { if (first === void 0) { first = 0; } if (last === void 0) { last = items.length; } var currentFirst = first; var currentLast = last; while (currentFirst < currentLast) { var ix = (currentFirst + currentLast) / 2 | 0; var d = compare(items[ix]); if (d < 0) { currentFirst = ix + 1; } else if (d > 0) { currentLast = ix; } else { return ix; } } return currentFirst; } // export function findFirst(items, compare, first = 0, last = items.length) { // let ix = find(items, compare, first, last); // while (ix >= first && !compare(items[ix])) ix--; // return ix + 1; // } // // export function findLast(items, compare, first = 0, last = items.length) { // let ix = find(items, compare, first, last); // while (ix <= last && !compare(items[ix])) ix++; // return ix; // } // // export function findRange() {} module.exports = exports.default;