To practice working with arrays and hashes I use a fun lotto app. Could someone please explain to me why result.delete(i) deleted the whole result array? Isn't is suppose to delete just THAT element and return the rest of the array?( using result - [i] works as intended):
for i in 1..number_of_balls do # taking each possible ball
results.each do |result| # going through results
if result.include?(i) # find result that contains that ball
#result.delete(i) # delete itself from the result
matched_numbers[i]<< result - [i]
end
end
end
Here are my inputs:
number_of_balls = 49
results = [[3,11,12,14,41,43,13],[8,33,36,37,39,41,9], [1,6,23,24,27,39,34],
[3,9,10,13,20,43,34], [5,14,21,31,34,47,45],[8,20,21,25,31,41,33],
[18,25,28,33,36,42,7],[7,16,17,31,40,48,26],[5,10,23,27,37,38,33],
[4,15,30,37,46,48,3], [7,9,21,33,38,42,45], [11,17,19,20,36,43,9],
[7,14,17,20,37,47,34],[25,28,29,30,35,44,3],[8,18,36,39,41,47,31],
[9,12,13,14,44,48,18],[4,14,18,40,43,44,5], [13,16,18,34,35,36,26],
[11,23,25,28,29,36,27]]
Desired output:
[[11, 12, 14, 41, 43, 13], [9, 10, 13, 20, 43, 34], [4, 15, 30, 37, 46, 48],
[25, 28, 29, 30, 35, 44], [4, 19, 33, 34, 48, 39], [4, 9, 10, 11, 43, 46],
[5, 6, 33, 38, 39, 8], [2, 7, 21, 22, 30, 33], [1, 19, 31, 32, 47, 37],
[17, 20, 30, 35, 48, 26]]
deleteactually deletes all the element in the array that matchesi.