Skip to main content

Solution 3: Find the Repeat

Given an array with at least two elements, return the element which is included more than once. If no element repeats, return false. If more than one element repeats, return any one of the repeating elements.

def find_repeat(array)
seen = []
for element in array
return element if seen.include? element
seen.push element
end
false
end