documentcloud/underscore — pull request #621 by sugendran (2012-05-29 23:46:01+00:00)
Title: Adds a binary find/search for sorted arrays

As per pull request #620, with the code fixed to take an iterator like the sort function.

The aim of the bfind method is to tackle the following scenario

// this array is sorted by key then parentKey
var array = [
{ key: "bar", parentKey: "zoo",value: "magic" },
{ key: "foo", parentKey: "bar", value: "hat" },
{ key: "foo", parentKey: "monkey", value: "pants" }];

var thingToFind = { key: "foo", parentKey: "monkey" };

This is the scenario that I'm facing when I get data from my datasource. I know the key and parentKey and the array is sorted in that order - so the optimal way would be to find the object is a binary search.