summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/test/mochitest/code_binary_search.js
blob: c43848a60ce05d8531d774dc6484f5025b009936 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// Generated by CoffeeScript 1.6.1
(function() {

  window.binary_search = function(items, value) {
    var pivot, start, stop;
    start = 0;
    stop = items.length - 1;
    pivot = Math.floor((start + stop) / 2);
    while (items[pivot] !== value && start < stop) {
      if (value < items[pivot]) {
        stop = pivot - 1;
      }
      if (value > items[pivot]) {
        start = pivot + 1;
      }
      pivot = Math.floor((stop + start) / 2);
    }
    if (items[pivot] === value) {
      return pivot;
    } else {
      return -1;
    }
  };

}).call(this);

/*
//# sourceMappingURL=code_binary_search.map
*/