function bsearch(array, target) {
    let min = 0;
    let max = array.length - 1;
    while (max >= min) {
        let mid = Math.floor((min + max) / 2)
        if (target === array[mid]) {
            return mid;
        }
        if (target > array[mid]) {
            min = mid + 1;
        } else {
            max = mid - 1
        }
    }
    return -1
}
console.log(bsearch([1, 2, 3, 4, 5, 6, 7], 0))

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: