binarysearch
Advanced tools
Comparing version 0.2.2 to 0.2.3
23
index.js
@@ -60,5 +60,5 @@ | ||
var cmp = comparitor(arr[closest],search); | ||
if(cmp === -1) {//less | ||
if(cmp < 0) {//less | ||
arr.splice(++closest,0,search); | ||
} else if(cmp === 1){ | ||
} else if(cmp > 0){ | ||
arr.splice(closest,0,search); | ||
@@ -121,5 +121,3 @@ } else { | ||
return index.sort(function(o1,o2){ | ||
if(o1.v>o2.v) return 1 | ||
else if(o1.v<o2,v) return -1 | ||
else return 0; | ||
return o1.v - o2.v; | ||
}); | ||
@@ -129,3 +127,3 @@ } | ||
module.exports.cmp = function(v1,v2){ | ||
return (v1<v2?-1:v1>v2?1:0) | ||
return v1 - v2; | ||
} | ||
@@ -139,3 +137,2 @@ | ||
if(typeof v === 'object' && v.hasOwnProperty('v')) indexMode = true; | ||
indexMode = false; | ||
if(typeof search === 'object' && search.hasOwnProperty('v')) indexModeSearch = true | ||
@@ -147,5 +144,3 @@ } | ||
if(v > search) return 1; | ||
else if(v < search) return -1; | ||
return 0; | ||
return v - search; | ||
}; | ||
@@ -166,5 +161,5 @@ }; | ||
if (cmp === -1) { | ||
if (cmp < 0) { | ||
min = middle + 1; | ||
} else if (cmp === 1) { | ||
} else if (cmp > 0) { | ||
max = middle - 1; | ||
@@ -188,6 +183,6 @@ } else { | ||
if(invert){ | ||
if (cmp === 1)max = middle - 1; | ||
if (cmp > 0)max = middle - 1; | ||
else min = middle; | ||
} else { | ||
if (cmp === -1)min = middle + 1; | ||
if (cmp < 0)min = middle + 1; | ||
else max = middle; | ||
@@ -194,0 +189,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.2", | ||
"version": "0.2.3", | ||
"repository": { | ||
@@ -6,0 +6,0 @@ "url": "git://github.com/soldair/node-binarysearch.git" |
@@ -6,5 +6,3 @@ var test = require('tap').test; | ||
var key = bs([1,2,3,4,5,6,7,8],6,function(v,find){ | ||
if(v > find) return 1; | ||
else if(v < find) return -1; | ||
else return 0 | ||
return (v - find); | ||
}); | ||
@@ -11,0 +9,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13617
308