mirror of
https://github.com/TheAlgorithms/Ruby
synced 2025-01-18 10:26:54 +01:00
Pass rubocop
This commit is contained in:
parent
00a3e61cfe
commit
e2a03f33c4
1 changed files with 6 additions and 9 deletions
|
@ -5,18 +5,15 @@ def double_linear_search(array, search_item)
|
||||||
end_ind = array.length - 1
|
end_ind = array.length - 1
|
||||||
|
|
||||||
while start_ind <= end_ind
|
while start_ind <= end_ind
|
||||||
if array[start_ind] == search_item
|
return start_ind if array[start_ind] == search_item
|
||||||
return start_ind
|
return end_ind if array[end_ind] == search_item
|
||||||
elsif array[end_ind] == search_item
|
|
||||||
return end_ind
|
start_ind += 1
|
||||||
else
|
end_ind -= 1
|
||||||
start_ind += 1
|
|
||||||
end_ind -= 1
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# returns -1 if search_item is not found in array
|
# returns -1 if search_item is not found in array
|
||||||
return -1
|
-1
|
||||||
end
|
end
|
||||||
|
|
||||||
puts(double_linear_search([1, 5, 5, 10], 1))
|
puts(double_linear_search([1, 5, 5, 10], 1))
|
||||||
|
|
Loading…
Reference in a new issue