I'm for some reason hitting a wall here. I need help figuring this out please. I have the following type of 2D array:
[["Bob", "Car", 25000],
["Bob", "TV", 5000],
["Bob", "dog", 1000],
["Sue", "Cat", 1000],
["Sue", "Car", 10000],
["Bob", "shoes", 100],
["Carol", "car", 20000]]
And I need to generate an array that is the sum of each of these people's total from the third element of each sub array. ie:
[["Bob", 31100],
["Sue", 11000],
["Carol", 20000]]
Right now I have a complicated and contrived solution using two loops that iterate through the entire array for each of its own elements. Is there an easier more streamlined way to do this? Especially since my data sets will be quite large. I know ruby has a bunch of awesome enumerables that seem like would fit here, but I can't quite think of how to fit them in.
arr = [['Bob', 'Car', 25000],...]. That way, readers can refer toarrin answers and comments without having to define it.