mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-05 16:26:47 +08:00
Update jumpSearch.js
This commit is contained in:
@ -9,8 +9,7 @@ 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)
|
||||
{
|
||||
while (arr[Math.min(step, length) - 1] < value) {
|
||||
lowerBound = step;
|
||||
step += step;
|
||||
if (lowerBound >= length) {
|
||||
@ -19,8 +18,7 @@ const jumpSearch = (arr, value)=>{
|
||||
}
|
||||
|
||||
const upperBound = Math.min(step, length);
|
||||
while (arr[lowerBound] < value)
|
||||
{
|
||||
while (arr[lowerBound] < value) {
|
||||
lowerBound++;
|
||||
if (lowerBound === upperBound) {
|
||||
return -1;
|
||||
|
Reference in New Issue
Block a user