Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save yclim95/3b627b323e0c8e889e21 to your computer and use it in GitHub Desktop.
Save yclim95/3b627b323e0c8e889e21 to your computer and use it in GitHub Desktop.
def linear_search(num, array_num)
counter=0
until array_num[counter]==num || array_num[counter] == nil
counter+=1
end
puts array_num[counter]==num ? counter : "nil"
end
def checking(num1, num2)
return true if num1==num2
false
end
def global_linear_search(object, array_object)
counter=0
position=[]
while counter<array_object.length
position << counter if array_object[counter]==object
counter+=1
end
p position
end
random_numbers = [6, 29, 18, 2, 72, 19, 18, 10, 37]
linear_search(18, random_numbers) # ==>2
linear_search(9, random_numbers) # ==>nil
bananas_arr = "bananas".split(//)
global_linear_search("a",bananas_arr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment