Skip to content

Instantly share code, notes, and snippets.

@leopolicastro
Last active March 11, 2022 10:47
Show Gist options
  • Save leopolicastro/787c7e6d20cc3254eec5b2ff79fdb57c to your computer and use it in GitHub Desktop.
Save leopolicastro/787c7e6d20cc3254eec5b2ff79fdb57c to your computer and use it in GitHub Desktop.
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