From 01ca43d3fd74ca6d5ad2aa2e5c7e4a464e9ecec2 Mon Sep 17 00:00:00 2001 From: GohJunLe <108907711+GohJunLe@users.noreply.github.com> Date: Sat, 3 Sep 2022 17:28:47 +0800 Subject: [PATCH] Update exponentialSearch.js --- .../search/exponential-search/exponentialSearch.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/algorithms/search/exponential-search/exponentialSearch.js b/src/algorithms/search/exponential-search/exponentialSearch.js index eef84a6e..d6588156 100644 --- a/src/algorithms/search/exponential-search/exponentialSearch.js +++ b/src/algorithms/search/exponential-search/exponentialSearch.js @@ -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); -} \ No newline at end of file +}