implementation of binary search


arr = [1,2,3,4,5,6,8,9,45,323,767]
n = arr.length;
x=323

function binary(arr,x){
let start = 0;
let end = n;
while(start<=n){
let middle = Math.floor((start+end)/2);
if(arr[middle]===x){
return middle;
}
else if(arr[middle]>x){
start=middle+1;
}
else(arr[middle]<x)
start=middle-1;

}
return -1;
}

let result = binary(arr,x)
console.log(value is ${x})
if(result != -1){
console.log(here is searched element ${result})}
else{
console.log(hello this is even exisit)
}