My Binary Search Solution is better than yours
Dimer Bwimba
Posted on May 7, 2021
const binary = (val, arr) => {
let lower = 0;
let upper = arr.length - 1;
while (lower <= upper) {
console.log("ols");
const middle = lower + Math.floor((upper - lower) / 2);
if (val === arr[middle]) {
return middle;
}
if (val < arr[middle]) {
console.log("right");
upper = middle - 1;
} else {
console.log("left");
lower = middle + 1;
}
}
return -1;
};
đź’– đź’Ş đź™… đźš©
Dimer Bwimba
Posted on May 7, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.