Junior — Senior
Searching for an element in a sorted array using binary search method
livecode
Task condition
Given a sorted sequence of numbers. It is required to determine the position of a given value in the array: if the value is present — return its index, if absent — return -1.
const sortedArr = [-1, 0, 3, 5, 9, 12];
console.log(binarySearch(sortedArr, 9)); // 4