@aegenet/belt-binary-search
Version:
Binary search
3 lines (2 loc) • 861 B
JavaScript
(function(o,t){typeof exports=="object"&&typeof module<"u"?t(exports):typeof define=="function"&&define.amd?define(["exports"],t):(o=typeof globalThis<"u"?globalThis:o||self,t(o["@aegenet/belt-binary-search"]={}))})(this,function(o){"use strict";function t(f,i,n,u=0,l=f.length){const e=Math.floor(u+(l-u)/2),r=n(f[e],i);return r!==0&&(e===0||e===f.length-1)?null:r>0?e===l?null:t(f,i,n,u,e):r<0?e===u?null:t(f,i,n,e,l):{value:f[e],index:e}}function y(f,i,n){if(!n)if(typeof i=="string")n=(l,e)=>l.localeCompare(e);else if(typeof i=="number"||typeof i=="bigint")n=(l,e)=>l-e;else throw new Error("Invalid usage: you must specify a comparator if your searchValue is an object.");const u=f.slice(0).sort(n);return t(u,i,n)}o.binarySearch=t,o.safeBinarySearch=y,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})});
//# sourceMappingURL=index.umd.js.map