Target number to match against.
Non-empty list of candidates; order matters for tie-breaking.
Which candidate wins when distances are equal. Defaults to "first".
The item in items closest to value, using bias to break ties.
const items = [9, 7, 5, 3, 1];
findNearest(4, items); // 5 (default bias: "first")
findNearest(4, items, "last"); // 3
findNearest(4, items, "smaller"); // 3
findNearest(4, items, "larger"); // 5
When items is empty (via isPopulatedArray).
Returns the closest value in
items, with configurable tie-breaking.Bias options:
"first"/"last"keep the earlier or later tied candidate;"smaller"/"larger"prefer the numerically smaller or larger tied value.