I'm fairly new to learning Ruby so please bear with me. I am working on a 7 kyu Ruby coding challenge and I've been tasked with finding how many people are left on the bus (first value represents people on, second value, people off) please look at comments in code for more detail.
below is a test example:
([[10, 0], [3, 5], [5, 8]]), # => should return 5"
This is my solution so far:
def number(bus_stops)
bus_stops.each{ | on, off | on[0] -= off[1] }
end
bus_stops
# loop through the array
# for the first array in the nested array subtract second value from first
# add the sum of last nested array to first value of second array and repeat
# subtract value of last element in nested array and repeat
How can I approach this? any resources you would recommend?
arr = [[10, 0], [3, 5], [5, 8]]). That way readers can refer to the variables (e.g.,arr) in answers and comments without having define them. Also, inputs should all be valid Ruby objects. Yours is not valid, because of the comma, and the parentheses are superfluous. The expected result should always be shown, which here you have done.