From e37d184e70aae70dc3aeeb5a750d52dc6ab4e7a5 Mon Sep 17 00:00:00 2001 From: Lorenzo Bolla Date: Mon, 13 Jun 2011 07:19:01 -0700 Subject: [PATCH] Fix "integer overflow" bug. --- algorithms/searching/binary-search/binary-search.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/algorithms/searching/binary-search/binary-search.js b/algorithms/searching/binary-search/binary-search.js index b40ceb9..837d2fe 100644 --- a/algorithms/searching/binary-search/binary-search.js +++ b/algorithms/searching/binary-search/binary-search.js @@ -44,7 +44,7 @@ function binarySearch(items, value){ } //recalculate middle - middle = Math.floor((stopIndex + startIndex)/2); + middle = startIndex + Math.floor((stopIndex - startIndex)/2); } //make sure it's the right value