Skip to content

Instantly share code, notes, and snippets.

@emberlzhang
Created October 10, 2012 01:15
Show Gist options
  • Save emberlzhang/3862557 to your computer and use it in GitHub Desktop.
Save emberlzhang/3862557 to your computer and use it in GitHub Desktop.
Solution for Linear Search
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