Created
October 10, 2012 01:15
-
-
Save emberlzhang/3862557 to your computer and use it in GitHub Desktop.
Solution for 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 linear_search(obj, array) #3, [4,5,1,2,3] => 4 | |
index = 0 | |
for elem in array | |
if elem == obj | |
break | |
else | |
index += 1 | |
end | |
end | |
index | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment