Socket
Socket
Sign inDemoInstall

binary-search

Package Overview
Dependencies
Maintainers
3
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

binary-search - npm Package Compare versions

Comparing version 1.3.5 to 1.3.6

16

index.js

@@ -23,16 +23,18 @@ module.exports = function(haystack, needle, comparator, low, high) {

while(low <= high) {
/* Note that "(low + high) >>> 1" may overflow, and results in a typecast
* to double (which gives the wrong results). */
mid = low + (high - low >> 1);
// The naive `low + high >>> 1` could fail for array lengths > 2**31
// because `>>>` converts its operands to int32. `low + (high - low >>> 1)`
// works for array lengths <= 2**32-1 which is also Javascript's max array
// length.
mid = low + ((high - low) >>> 1);
cmp = +comparator(haystack[mid], needle, mid, haystack);
/* Too low. */
// Too low.
if(cmp < 0.0)
low = mid + 1;
/* Too high. */
// Too high.
else if(cmp > 0.0)
high = mid - 1;
/* Key found. */
// Key found.
else

@@ -42,4 +44,4 @@ return mid;

/* Key not found. */
// Key not found.
return ~low;
}
{
"name": "binary-search",
"version": "1.3.5",
"version": "1.3.6",
"description": "tiny binary search function with comparators",

@@ -5,0 +5,0 @@ "license": "CC0-1.0",

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