Update src/algorithms/search/exponential-search/exponentialSearch.js

Co-authored-by: codacy-production[bot] <61871480+codacy-production[bot]@users.noreply.github.com>
This commit is contained in:
GohJunLe 2022-09-03 17:21:15 +08:00 committed by GitHub
parent 8e37e8ff7a
commit dd1843f0ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -48,7 +48,7 @@ export default function exponentialSearch(sortedArray, seekElement, comparatorCa
// Find range for binary search by repeated doubling
let range = 1;
while (range < length && comparator.lessThanOrEqual(sortedArray[range], seekElement)) {
range = range * 2;
range *= 2;
}
// Call binary search for the found range.
return binarySearch(sortedArray, range/2, Math.min(range, length - 1), seekElement, comparatorCallback);