diff --git a/Search/jumpSearch.js b/Search/jumpSearch.js index 35afb6005..e9faefca5 100644 --- a/Search/jumpSearch.js +++ b/Search/jumpSearch.js @@ -5,31 +5,29 @@ * The advantage against binary search is that Jump Search traversed back only once. */ -const jumpSearch = (arr, value)=>{ - const length = arr.length; - let step = Math.floor(Math.sqrt(length)); - let lowerBound = 0; - while (arr[Math.min(step, length)-1] < value) - { - lowerBound = step; - step += step; - if (lowerBound >= length){ - return -1; +const jumpSearch = (arr, value) => { + const length = arr.length; + let step = Math.floor(Math.sqrt(length)); + let lowerBound = 0; + while (arr[Math.min(step, length) - 1] < value) { + lowerBound = step; + step += step; + if (lowerBound >= length) { + return -1; + } } - } - - const upperBound = Math.min(step, length); - while (arr[lowerBound] < value) - { - lowerBound++; - if (lowerBound === upperBound){ - return -1; + + const upperBound = Math.min(step, length); + while (arr[lowerBound] < value) { + lowerBound++; + if (lowerBound === upperBound) { + return -1; + } } - } - if (arr[lowerBound] === value){ - return lowerBound; - } - return -1; + if (arr[lowerBound] === value) { + return lowerBound; + } + return -1; } const arr = [0,0,4,7,10,23,34,40,55,68,77,90] jumpSearch(arr,4);