I have an array where the first row contain headers and the first column contains dates. And the last column in the array is for Totals.
[["date", "Fish", "Bear", "Cat", "Total"],
["8/1/2014", 5, 3, 6, 0],
["8/1/2014", 2, 6, 3, 0]]
I need to sum up the values of columns per row and update the last column with that value. Here's what I've done thus far. It's the part where I actually change the value of the array I can't quit get.
arr.each_with_index do |row,index|
sum = 0
next if index == 0
row.each_with_index do |col,index2|
next if index2 ==0
if (col == row.last)
#update the col with the value of sum
end
sum += col.to_i
end
end
PS: My apologies if I haven't formatted this correctly. I'm trying to learn how to make my questions look nice.