function binarySearch(array, value) {
var low = 0;
var high = array.length - 1;
var middle;
while (low <= high) {
middle = (low + high) / 2;
if (array[middle] > value) {
high = middle - 1;
} else if (array[middle] < value) {
low = middle + 1;
} else {
return middle;
}
}
}