mbostock/d3 — pull request #1767 by mbostock (2014-03-06 18:04:29+00:00)
Title: Add d3.bisectBy(comparator).

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.