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:20:12 +08:00 committed by GitHub
parent 295fb99242
commit 8e37e8ff7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -21,7 +21,7 @@ function binarySearch(sortedArray, startIndex, endIndex, seekElement, comparator
} }
// If element is smaller than middleIndex, then it can only be present n left subarray // If element is smaller than middleIndex, then it can only be present n left subarray
if (comparator.greaterThan(sortedArray[middleIndex], seekElement)) { if (comparator.greaterThan(sortedArray[middleIndex], seekElement)) {
return binarySearch(sortedArray, startIndex, middleIndex-1, seekElement, comparatorCallback); return binarySearch(sortedArray, startIndex, middleIndex - 1, seekElement, comparatorCallback);
} }
// Else the element can only be present in right subarray // Else the element can only be present in right subarray
return binarySearch(sortedArray, middleIndex + 1, endIndex, seekElement, comparatorCallback); return binarySearch(sortedArray, middleIndex + 1, endIndex, seekElement, comparatorCallback);