mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-05 00:01:37 +08:00
Remove live code & console.log, leave examples as comments (ProjectEuler, Recursive).
This commit is contained in:
@ -2,7 +2,7 @@
|
||||
// https://en.wikipedia.org/wiki/Binary_search_algorithm
|
||||
// Search the integer inside the sorted integers array using Binary Search Algorithm
|
||||
|
||||
const BinarySearch = (intArr, searchQuery) => {
|
||||
export const BinarySearch = (intArr, searchQuery) => {
|
||||
if (searchQuery === null || searchQuery === undefined || intArr.length === 0) {
|
||||
return false
|
||||
}
|
||||
@ -17,13 +17,3 @@ const BinarySearch = (intArr, searchQuery) => {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// testing
|
||||
(() => {
|
||||
console.log('Number Present with odd array length: 5 = ', BinarySearch([1, 2, 3, 4, 5, 6, 7], 5))
|
||||
console.log('Number Present with even array length: 5 = ', BinarySearch([1, 2, 4, 5, 6], 5))
|
||||
console.log('Number Present with only single element: 5 = ', BinarySearch([5], 5))
|
||||
console.log('Number Not Present: 0 = ', BinarySearch([1, 2, 3, 4, 5], 0))
|
||||
console.log('Undefined number search query = ', BinarySearch([1, 2, 3, 4, 5]))
|
||||
console.log('With Empty array = ', BinarySearch([], 1))
|
||||
})()
|
||||
|
Reference in New Issue
Block a user