~openteachermaintainers/openteacher/3.x

« back to all changes in this revision

Viewing changes to node_modules/ot-bisect/index.js

  • Committer: Marten de Vries
  • Date: 2017-06-28 18:05:48 UTC
  • Revision ID: git-v1:b4c406307aa345c58b9904b76580f15c5bff2a4e
Move JS into npm modules

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
        Copyright 2013, 2017, Marten de Vries
 
3
 
 
4
        This file is part of OpenTeacher.
 
5
 
 
6
        OpenTeacher is free software: you can redistribute it and/or modify
 
7
        it under the terms of the GNU General Public License as published by
 
8
        the Free Software Foundation, either version 3 of the License, or
 
9
        (at your option) any later version.
 
10
 
 
11
        OpenTeacher is distributed in the hope that it will be useful,
 
12
        but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
        GNU General Public License for more details.
 
15
 
 
16
        You should have received a copy of the GNU General Public License
 
17
        along with OpenTeacher.  If not, see <http://www.gnu.org/licenses/>.
 
18
*/
 
19
 
 
20
module.exports = function bisect(a, x) {
 
21
        var low = 0;
 
22
        var high = a.length;
 
23
 
 
24
        while (low < high) {
 
25
                var mid = Math.floor((low + high) / 2);
 
26
                if (x < a[mid]) {
 
27
                        high = mid;
 
28
                } else {
 
29
                        low = mid + 1;
 
30
                }
 
31
        }
 
32
        return low;
 
33
};