Implement a function that performs binary search on an array of numbers. The function should take in a sorted array of integers and a target integer to find. It returns the index of the target element or -1, if the target element doesn't exist in the array.
Examples
binarySearch([1,2,3,6,9,11],6);// 3
binarySearch([1,2,3,12,14,16],5);// -1
Hints
New
Asked at these companies
Unlock company signalsPremium shows which companies ask this question so you can prioritize practice by target company.