Created
November 5, 2021 16:45
-
-
Save ramsunvtech/2e7d7eeabbb78363d51f45aada0694de to your computer and use it in GitHub Desktop.
Binary Search Iterative
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function binarySearchIterative(inputArray, searchTerm) { | |
let left = 0; | |
let right = inputArray.length - 1; | |
while(left <= right) { | |
const midPoint = Math.floor((left + right) / 2); | |
if (inputArray[midPoint] === searchTerm) { | |
return true; | |
} else if (searchTerm < inputArray[midPoint]) { | |
right = midPoint - 1 | |
} else { | |
left = midPoint + 1; | |
} | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment