Skip to content

Instantly share code, notes, and snippets.

View xihai01's full-sized avatar
🎯
Focusing

Xihai Luo xihai01

🎯
Focusing
View GitHub Profile
@xihai01
xihai01 / binarySearch.js
Created February 13, 2022 16:58
BInary Search Implementation in JS
const binarySearch = function (array, target) {
// initialise variables to point to bounds of array
let bottom = 0;
let top = array.length - 1;
let middle;
while (bottom <= top) {
// get index of middle value
middle = Math.floor((bottom + top) / 2);
const middleValue = array[middle];