Created
September 27, 2017 02:40
-
-
Save sergiomaia/f63e09578f1d599f5faaf72fc16a8732 to your computer and use it in GitHub Desktop.
Ruby Algorithm - Linear Search
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 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