browser/devtools/debugger/test/code_binary_search.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:d04de1455f9a
1 // Generated by CoffeeScript 1.6.1
2 (function() {
3
4 window.binary_search = function(items, value) {
5 var pivot, start, stop;
6 start = 0;
7 stop = items.length - 1;
8 pivot = Math.floor((start + stop) / 2);
9 while (items[pivot] !== value && start < stop) {
10 if (value < items[pivot]) {
11 stop = pivot - 1;
12 }
13 if (value > items[pivot]) {
14 start = pivot + 1;
15 }
16 pivot = Math.floor((stop + start) / 2);
17 }
18 if (items[pivot] === value) {
19 return pivot;
20 } else {
21 return -1;
22 }
23 };
24
25 }).call(this);
26
27 /*
28 //# sourceMappingURL=code_binary_search.map
29 */

mercurial