Last active
March 11, 2022 10:47
-
-
Save leopolicastro/787c7e6d20cc3254eec5b2ff79fdb57c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def linear_search(sorted_array, search_value) | |
sorted_array.each_with_index do |element, index| | |
if element == search_value | |
return index | |
elsif element > search_value | |
break | |
end | |
end | |
nil | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment