Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

binarysearch

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

binarysearch - npm Package Compare versions

Comparing version 0.2.1 to 0.2.2

b.js

58

index.js

@@ -32,3 +32,3 @@

opts = opts||{};
if(!comparitor) comparitor = module.exports._defaultComparitor();
if(!comparitor) comparitor = this._defaultComparitor();

@@ -127,2 +127,6 @@ var closest = bsclosest(arr, search, comparitor, opts.end, opts.exists?false:true);

module.exports.cmp = function(v1,v2){
return (v1<v2?-1:v1>v2?1:0)
}
module.exports._defaultComparitor = function() {

@@ -157,3 +161,3 @@ var indexMode,indexModeSearch;

cmp = comparitor(arr[middle],search);
cmp = comparitor(arr[middle],search,middle);

@@ -173,43 +177,29 @@ if (cmp === -1) {

function bsclosest(arr, search, comparitor, invert, closest) {
var mids = {};
var min = 0,max = arr.length-1,middle,cmp;
var sanity = arr.length;
var mids = {}
, min = 0,max = arr.length-1,middle,cmp
, sanity = arr.length;
while (min < max) {
middle = midCareful(min, max,mids);
cmp = comparitor(arr[middle],search);
cmp = comparitor(arr[middle],search,middle);
if(invert){
if (cmp === 1){
max = middle - 1;
} else {
min = middle;
}
if (cmp === 1)max = middle - 1;
else min = middle;
} else {
if (cmp === -1){
min = middle + 1;
} else {
max = middle;
}
if (cmp === -1)min = middle + 1;
else max = middle;
}
sanity--;
if(!sanity) {
break;
}
if(!--sanity) break;
}
if (max == min && comparitor(arr[min],search) === 0) return min;
if (max == min && comparitor(arr[min],search) === 0) {
return min;
} else {
if(closest) {
var match = comparitor(arr[min],search);
if(min == arr.length-1 && match === -1) return min;
if(min == 0 && match === 1) return 0;
if(closest) {
var match = comparitor(arr[min],search);
if(min == arr.length-1 && match === -1) return min;
if(min == 0 && match === 1) return 0;
return closest?(invert?min+1:min-1):-1;
}
return -1;
}
return closest?(invert?min+1:min-1):-1;
}
return -1;
}

@@ -216,0 +206,0 @@

{
"name": "binarysearch",
"description": "pure js binary search for sorted javascript arrays||array like objects. returns any || last || first || closest matched key for value, or slice between 2 values where values need not exist.",
"version": "0.2.1",
"version": "0.2.2",
"repository": {

@@ -6,0 +6,0 @@ "url": "git://github.com/soldair/node-binarysearch.git"

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc