mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-07 19:17:33 +08:00
Code Refacoring
This commit is contained in:
@ -28,9 +28,7 @@ function binarySearchRecursive (arr, x, low = 0, high = arr.length - 1) {
|
|||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function binarySearchIterative (arr, x, low = 0, high = arr.length - 1) {
|
function binarySearchIterative (arr, x, low = 0, high = arr.length - 1) {
|
||||||
|
|
||||||
while (high >= low) {
|
while (high >= low) {
|
||||||
const mid = Math.floor(low + (high - low) / 2)
|
const mid = Math.floor(low + (high - low) / 2)
|
||||||
|
|
||||||
@ -51,7 +49,6 @@ function binarySearchIterative (arr, x, low = 0, high = arr.length - 1) {
|
|||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ---------------------------------- Test ---------------------------------- */
|
/* ---------------------------------- Test ---------------------------------- */
|
||||||
|
|
||||||
const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
|
const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
|
||||||
|
Reference in New Issue
Block a user