I have a sorted array: 

```
[0, 1, 1, 2, 3, 4, 6, 6, 6, 50, 70, 80, 81, 100, 10000]

```

I am trying to use a binary search to parse this sorted array and return all values of the array that are greater or equal to a given value. So if I feed my search `6`, the resulting array I desire would be:

```
[6, 6, 6, 50, 70, 80, 81, 100, 10000]

```

I cannot just look for the first occurence of a value, because the value may not be present in the array. For example, I may have to look for `5`, which is not present, but my output would need to be the same as above.

I have some code here that is stuck in an infinite loop at this jsFiddle: <http://jsfiddle.net/2mBdL/691/>

```
var arr = [0, 1, 1, 2, 3, 4, 6, 6, 6, 50, 70, 80, 81, 100, 10000];

function binarySearch(arr, i) {
    var mid = Math.floor(arr.length / 2);
    var leftOfMid = mid - 1;
    console.log(arr[mid], i);

    if (arr[mid] == i && arr[leftOfMid] == i) {
        console.log('needle is exactly at 6, but left is same, checking lower half', arr[mid], i);
        binarySearch(arr.splice(leftOfMid, Number.MAX_VALUE), i);
    } else if (arr[mid] < i && arr.length > 1) {
        console.log('needle is at a value that is less than 6', arr[mid], i);
        binarySearch(arr.splice(mid, Number.MAX_VALUE), i);
    } else if (arr[mid] > i && arr.length > 1) {
        console.log('needle is at a value that is higher than 6 days', arr[mid], i);
        binarySearch(arr.splice(0, mid), i);
    } else if (arr[mid] == i && arr[leftOfMid] < i) {
        console.log('MATCH, needle is the beginning of the range', arr[mid], i);
        return arr[mid];
    }
    else {
        console.log('not here', i);d
        return -1;
    }

}

var result = binarySearch(arr, 6);
console.log(result);

```

How could I utilize a binary search for this use case? The array can get very large, so I am really trying to get this to work!