Implement the binarySearch function.
It should accept a sorted array and a number.
It should return the position of the number in the array or -1 if it’s not found.

You can’t use any third party modules or built in Array functions.
P.S. If you’ve forgotten the details, go back to one of the intro lectures and find the pseudocode implementation.

This task is part of the Full-Stack JavaScript Course
If you have any issues with it, you can ask for community help below the post
Feel free to help others if you’ve already solved the task

helper.js

export const binarySearch = (arr, x) => {
// implement binary search algorithm here
}

solution.js

/**
 * Implement the binarySearch function.
 *
 * It should accept a sorted array and a number.
 *
 * It should return the position of the number in the array or -1 if it's not found.
 *
 * You can't use any third party modules or built in Array functions.
 *
 * P. S. If you've forgotten the details, go back to one of the intro lectures and find the pseudocode implementation.
 * */

import { binarySearch } from './helper.js';

const arr = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ];

console.log(binarySearch(arr, 22));