[ create a new paste ] login | about

Link: http://codepad.org/jUgepFQa    [ raw code | output | fork ]

Ruby, pasted on Aug 27:
1
2
3
4
5
6
7
8
9
10
11
12
def binary_search(arr,n)
	ind = arr.index(n)
	if ind == nil
		return -1
	else	
		return ind
	end
end


puts binary_search([1,2,3,4,5],245)
puts binary_search([1,2,3,4,5],3)


Output:
1
2
-1
2


Create a new paste based on this one


Comments: