JSFiddle - React, Tailwind, and code Playground
by Sudheer Nunna
JavaScript
const binarySearch = (sortedArray,target)=>{
debugger
console.log("asdasfa")
let start = 0;
let end = sortedArray.length-1;
/* while(start<=end){
const mid =Math.floor((start+end)/2);
if(sortedArray[mid]===target){
return mid;
}else if(sortedArray[mid] < target){
start = mid+1;
}else{
end = mid-1;
}
} */
return -1;
}
const sortedArray = [1, 2, 3, 4, 5, 6, 7, 8, 9];
const targetValue = 7;
const result = binarySearch(sortedArray, targetValue);
console.log(result);