I am quite new to ruby so bear with me, I have two arrays and we are meant to find the number which is missing.
The starting array sequence is [1,2,3,4,5,6,7,8,9] The mixed array with one deleted number is 5 [3,2,4,6,7,8,1,9]
My idea is to add up each array and see which number is missing- I started to produce a method (I know it is shabby but I am learning)
def find_deleted_number(arr, mixed)
arr = [1,2,3,4,5,6,7,8,9]
mixed = [3,2,4,6,7,8,1,9]
y = arr.inject(0){|sum,x| sum + x }
x = mixed_arr.inject(0){|total, y| total + y}
return y - x
end
Could anyone guide me to what I am doing wrong here?