Skip to content

Latest commit

 

History

History
26 lines (16 loc) · 775 Bytes

README.md

File metadata and controls

26 lines (16 loc) · 775 Bytes

Build status

SearchSortedNearest

This package provides a single function:

searchsortednearest(a, x; by=<transform>, lt=<comparison>, distance=(a,b)->abs(a-b), rev=false)

Find the index of (sorted) collection a that has the smallest distance to x.
Ties go to the smallest index.

Examples

using SearchSortedNearest

searchsortednearest(1:10, 1.1) == 1
searchsortednearest(1:10, 1.9) == 2

Attribution

This implementation is based on code provided by @traktofon on the Julia Discourse.