2.0.0 • Published 7 years ago

closest-to v2.0.0

Weekly downloads
66
License
MIT
Repository
github
Last release
7 years ago

closest-to

closest-to finds the closest value to a given target in a sorted array of numbers

Build status

Browser support

Install

npm install closest-to

Usage

require('closest-to')(needle, haystack, [returnIndex])
require('closest-to/nd')(needle, haystack, [returnIndex])
closest(10, [1, 3, 5, 7, 9])
> 9
closest(10, [1, 3, 5, 7, 9], true)
> 4
ndclosest([1, 2], [[1, 1], [2, 3], [3, 4]])
> [1, 1]

ndclosest([1, 2], [[1, 1], [2, 3], [3, 4]], true)
> 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)

License

MIT

2.0.0

7 years ago

1.0.1

7 years ago

1.0.0

8 years ago

0.1.0

10 years ago

0.0.2

11 years ago

0.0.1

11 years ago

0.0.0

11 years ago