Q display 0 and not the value of c, what is wrong with these code? Am i wrong in the return statement?
main js file
var q=0;
search(a,21,q);
document.getElementById("demo1").innerHTML = q;
another js file
function search(array, target, c) {
left = 0;
right = array.length - 1;
while (left <= right) {
mid = (left + right) / 2;
if (array[Math.trunc(mid)] == target) {
c = Math.trunc(mid);
console.log(c);
return array, target, c;
} else if (target < array[mid]) {
right = Math.trunc(mid) - 1;
} else {
left = Math.trunc(mid) + 1;
}
}
}