2.0.0 • Published 5 years ago

bsc v2.0.0

Weekly downloads
134
License
MIT
Repository
github
Last release
5 years ago

bsc npm

Binary search with comparator.

  • tests not only for the result but for how many steps it takes as well
  • always return -1 if nothing has been found, no "insertion point" negative values
  • no "lower" or "upper bounds"

Install

$ yarn add bsc

Usage

<T>(arr: T[], comparator: (item: T) => number) => number
import binarySearch from 'bsc'

const arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

// if comparator return `0` then that item is the result index
binarySearch(arr, (item) => 2 - item) // 2
binarySearch(arr, (item) => 10 - item) // -1
2.0.0

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.0

7 years ago