I have a Hash
that indexes a bunch of IDs to a value, something like:
hash = {1: 3.00, 2: 4.00, 3: 2.00, 4: 15.00, 5: 12.00, 6: 1.00}
I have an Array that looks like:
arr = [2, 3, 6]
What's a short, Ruby idiomatic way to iterate over my Array and add up the cumulative total from the corresponding keys in the Hash?
The result of the above would equal:
4.00 + 2.00 + 1.00 == 7.00