Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
binary-search-maa
Advanced tools
A function that takes in a sorted array (arr), an item to search (srch) and optionally a compare function (compareFunction) used to compare elements in array
The compare function takes two arguments a and b and should return a number < 0 if a < b, 0 if a = b, and a number > 0 if a > b)
The search returns an object ({found: boolean, index: number}) with 'found' property to indicate if srch was found in arr, and an 'index' property indicating the first occurence of srch if it was found or the index to insert srch in so as array is still sorted (might be arr.length if srch is greater than all items in array)
import binarySearch from 'binary-search';
const { found, index } = binarySearch([0, 1, 2, 4], 1);
// found = true, index = 1
const { found, index } = binarySearch([0, 1, 2, 4], 3);
// found = false, index = 3
const { found, index } = binarySearch([0, 1, 2, 4], 4);
// found = true, index = 3
const { found, index } = binarySearch([0, 1, 1, 1, 1, 1, 2, 4], 1);
// found = true, index = 1(always)
// demo usage to insert srch in arr in the correct position if it does not exists
const { found, index } = binarySearch(arr, srch);
if(!found) {
arr.splice(index, 0, srch);
}
// can send a comparison function, e.g. sorted desc:
const { found, index } = binarySearch([4, 2, 1, 0], 1, (a, b) => b - a);
// found = true, index = 2
FAQs
a small es6+ module to binary search sorted arrays
We found that binary-search-maa demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.