Assuming you can use the .include? method here is what I would do.
initialize new empty array
Iterate over original array
Check if current element in iteration is in new array
If not add it to new array
Return new array
I would suggest trying to implement the algorithm above before looking at the solution below.
def unique(original_array)
# Step 1)
unique_array = []
# Step 2)
for number in original_array do
# Step 3)
if !(unique_array.include? number)
# Step 4)
unique_array.push number
end
end
# Step 5)
return unique_array
end
Hope this helps.