Yngvarr

Generation

generate functionFri, 14 Apr 2023

search in array

function binarySearch(arr, target) { let start = 0 let end = arr.length - 1 while (start <= end) { const mid = Math.floor((start + end) / 2) if (arr[mid] === target) { return mid } else if (arr[mid] < target) { start = mid + 1 } else { end = mid - 1 } } return -1 }

Javascript
Generate More

Questions about programming?Chat with your personal AI assistant