array-binarysearch.closest
Advanced tools
Comparing version 0.1.3 to 0.2.0
12
index.js
@@ -1,3 +0,13 @@ | ||
function binarySearch(arr, val, bgn=0, end=arr.length) { | ||
function by(arr, val, fn, ths, bgn, end) { | ||
while(bgn<end) { | ||
var m = (bgn+end)>>>1, c = fn.call(ths, arr[m], val, m, arr); | ||
if(c<0) bgn = m+1; | ||
else if(c>0) end = m; | ||
else return m; | ||
} | ||
return bgn; | ||
}; | ||
function binarySearch(arr, val, fn, ths, bgn=0, end=arr.length) { | ||
if(fn!=null) return by(arr, val, fn, ths, bgn, end); | ||
while(bgn<end) { | ||
var m = (bgn+end)>>>1; | ||
@@ -4,0 +14,0 @@ if(arr[m]<val) bgn = m+1; |
{ | ||
"name": "array-binarysearch.closest", | ||
"version": "0.1.3", | ||
"version": "0.2.0", | ||
"description": "Get index of closest value in sorted array.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
1690
20
0