@bemoje/arr-sorted-has v1.0.2
@bemoje/arr-sorted-has
Binary search -based indexOf for sorted arrays.
Version
Travis CI
Dependencies
Stats
Donate
Installation
npm install @bemoje/arr-sorted-has
npm install --save @bemoje/arr-sorted-has
npm install --save-dev @bemoje/arr-sorted-hasUsage
import arrSortedHas from '@bemoje/arr-sorted-has'
const alpha = ['a', 'b', 'c']
arrSortedHas(alpha, 'b')
//=> true
arrSortedHas(alpha, 'e')
//=> false
const numeric = [2, 13, 20]
arrSortedHas(numeric, 20, {
numeric: true,
})
//=> trueTests
Uses Jest to test module functionality. Run tests to get coverage details.
npm run testAPI
Table of Contents
arrSortedHas
Binary search -based indexOf for sorted arrays.
Parameters
arrArray The array to searchelementany The element to findcompare(comparator | object)?compare.numericboolean Sort numerically. Defaults to lexicographic/alphabetic sort. (optional, defaultfalse)compare.descendingboolean Sort in descending order. Defaults to ascending order. (optional, defaultfalse)compare.arrayboolean Sort arrays. Nested arrays are also compared recursively. (optional, defaultfalse)compare.by(number | string | getter) Sort by either array index, a callback(element): any - or by object keys with dot-notation support. (optional, defaultundefined)
Returns boolean
comparator
Type: Function
Parameters
aany The first value to comparebany The second value to compare
Returns number A negative number if a > b, a positive number if a < b, 0 otherwise.
getter
Type: Function
Parameters
aany The value
Returns any The value to be compared