inputs = [
["9", "5", "4"],
["20", "40", "60"],
["1", "3", "19"]
]
numbers = inputs.sample
pp numbers
I’m trying to figure out how to add only the odd integers in the array together. So whenever I run the test, it’ll choose from the 3 rows and add them together.
I attempted to do it with an .each method to loop each integer but I keep running into errors.
sum = 0
numbers.each { |num| sum = num}
if pp num.to_i.odd?
pp num.to_i
end
Based on comment clarification:
For giggles, this is the fastest method I could find: