Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
45 lines (45 loc) · 960 Bytes

File metadata and controls

45 lines (45 loc) · 960 Bytes
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/**
* Binary Search Stubs for JS Arrays
* @license MIT
* @author Jim Chen
*/
var BinArray = (function(){
var BinArray = {};
BinArray.bsearch = function(arr, what, how){
if(arr.length === 0) {
return 0;
}
if(how(what,arr[0]) < 0) {
return 0;
}
if(how(what,arr[arr.length - 1]) >=0) {
return arr.length;
}
var low =0;
var i = 0;
var count = 0;
var high = arr.length - 1;
while(low<=high){
i = Math.floor((high + low + 1)/2);
count++;
if(how(what,arr[i-1])>=0 && how(what,arr[i])<0){
return i;
}
if(how(what,arr[i-1])<0){
high = i-1;
}else if(how(what,arr[i])>=0){
low = i;
}else {
console.error('Program Error');
}
if(count > 1500) { console.error('Too many run cycles.'); }
}
return -1; // Never actually run
};
BinArray.binsert = function(arr, what, how){
var index = BinArray.bsearch(arr,what,how);
arr.splice(index,0,what);
return index;
};
return BinArray;
})();
Morty Proxy This is a proxified and sanitized view of the page, visit original site.