From ca0f211fa6287ae32061c695762e4c0503dc43ed Mon Sep 17 00:00:00 2001 From: Nick Fisher Date: Thu, 26 Apr 2012 13:19:50 +0200 Subject: [PATCH] The 'needle' value is cached in sortedIndex --- underscore.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/underscore.js b/underscore.js index 590d2502f..cf8814f9f 100644 --- a/underscore.js +++ b/underscore.js @@ -289,10 +289,11 @@ // an object should be inserted so as to maintain order. Uses binary search. _.sortedIndex = function(array, obj, iterator) { iterator || (iterator = _.identity); + obj = iterator(obj); var low = 0, high = array.length; while (low < high) { var mid = (low + high) >> 1; - iterator(array[mid]) < iterator(obj) ? low = mid + 1 : high = mid; + iterator(array[mid]) < obj ? low = mid + 1 : high = mid; } return low; };