Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>JS Bin</title>
    </head>
    <body></body>
</html>
 
var numbers = [1, 3, 4, 6, 6.2, 99];
var valueToInsert = 2;
function sortedIndex(array, value) {
    var low = 0,
        high = array.length;
    while (low < high) {
        var mid = low + high >>> 1;
        if (array[mid] < value) low = mid + 1;
        else high = mid;
    }
    return low;
}
document.body.textContent = sortedIndex(numbers, valueToInsert);
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
creativitypro
0viewers