Skip to content
  • Mike Bostock's avatar
    Add d3.bisectBy(comparator). · 3c7cc81b
    Mike Bostock authored
    Fixes #1766. Unlike d3.bisector(accessor), this allows you to define a bisector
    that works in reverse order.
    
    An awkward aspect of implementing bisection on top of a comparator is that it is
    often the case that the sorted array contains objects (e.g., rows from a TSV),
    while the search value is a primitive value (e.g., a number). Thus, you want to
    apply an accessor to the array elements but not to the search value.
    
    The solution here is to invoke the comparator deterministically: the first
    argument is always an element from the array, and the second argument is always
    the search value. This lets a comparator apply an accessor to array elements but
    not to search values.
    3c7cc81b