So here is what I'm trying to do.
I have an array that contains more arrays of dates (which there are multiples of) and individual scores. It looks like this:
var example = [
["11/7/2015", 4],
["11/7/2015", 7],
["11/7/2015", 2],
["11/8/2015", 2],
["11/8/2015", 7],
["11/9/2015", 0],
["11/10/2015", 1]
];
My goal is to iterate through this entire array (it has around 900 cells), that can add/combine the scores of the dates that are similar, and overall removes all duplicate dates with the scores added together.
So the end result of the first array should look like this:
var example = [
["11/7/2015", 13],
["11/8/2015", 9],
["11/9/2015", 0],
["11/10/2015", 1]
];
As you can see, the duplicate dates were removed and the scores of each duplicate cell were added under one cell.
I tried doing this by using a for loop like this (using a duplicate of the array so I can use it as comparison to the original):
for(var i = 1; i < example.length; i--){
if(example[i][0] === dummyArray[i-1][0]){
example[i-1][1] += dummyArray[i][1];
example.splice(i,1);
} else{
}
}
But I can't use i-1 syntax inside the loop and not sure where to go from here. My goal is to do this in pure javascript and not use any libraries.