Skip to content

Instantly share code, notes, and snippets.

@sergiomaia
Created September 27, 2017 02:40
Show Gist options
  • Save sergiomaia/f63e09578f1d599f5faaf72fc16a8732 to your computer and use it in GitHub Desktop.
Save sergiomaia/f63e09578f1d599f5faaf72fc16a8732 to your computer and use it in GitHub Desktop.
Ruby Algorithm - Linear Search
def find_index(values, target)
values.each_with_index do |value, i|
return i if value == target
end
end
find_index([2, 4, 6, 8, 10, 12], 6)
# => 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment