0.1.4 • Published 6 years ago
array-binarysearch.comparator.last v0.1.4
array-binarysearch.comparator.last
Get index of last value in sorted (using comparator).
DEPRECATED: Please use array-binarysearch.last instead.
const binarySearch = require('array-binarysearch.comparator.last');
// binarySearch(<array>, <value>, <compare function>, [this], [begin=0], [end=array.length])
binarySearch([21, 42, 91, 91], 91, (a, b) => a===b? 0:(a<b? -1:1));
// 3
binarySearch(['G', 'KG', 'KG', 'MG'], 'g', (a, b, i) => a.toLowerCase().localeCompare(b.toLowerCase()), null, 1);
// -2 (-ve => not found, closest: ~(-2) = 1)
binarySearch(['G', 'KG', 'KG', 'MG'], 'KG', (a, b, i, arr) => a.localeCompare(b), null, 1, 4);
// 2