closest-to
closest-to finds the closest value to a given target in a sorted array of numbers
Install
npm install closest-to
Usage
needle haystack returnIndexneedle haystack returnIndex
> 9> 4
> 1 1 > 0
Benchmarks
closest-to@1.0.1 x 116,156 ops/sec ±1.02% (85 runs sampled)
closest-to@2.0.0 x 860,497 ops/sec ±1.09% (83 runs sampled)