mirror of
https://github.moeyy.xyz/https://github.com/trekhleb/javascript-algorithms.git
synced 2024-09-20 07:43:04 +08:00
Update exponentialSearch.js
This commit is contained in:
parent
f1d7c4b9aa
commit
01ca43d3fd
@ -42,7 +42,8 @@ export default function exponentialSearch(sortedArray, seekElement, comparatorCa
|
||||
const length = sortedArray.length;
|
||||
// If element is present at first location itself
|
||||
if (sortedArray.length !== 0) {
|
||||
if (comparator.equal(sortedArray[0], seekElement))
|
||||
if (comparator.equal(sortedArray[0], seekElement)){
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
// Find range for binary search by repeated doubling
|
||||
@ -52,4 +53,4 @@ export default function exponentialSearch(sortedArray, seekElement, comparatorCa
|
||||
}
|
||||
// Call binary search for the found range.
|
||||
return binarySearch(sortedArray, range/2, Math.min(range, length - 1), seekElement, comparatorCallback);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user