Currently, I am in the process of learning basic JavaScript and could use some assistance. My task involves working with two-dimensional arrays where the 0th index will always represent a date and the 1st index will always be an integer in the array. My goal is to create a new array consisting of unique objects with types A and B by summing up the values at the 1st index of each two-dimensional array. See the example code below:
$scope.mainArray = [{
type: 'A',
values: [
[111111, 12],
[111111, 12],
[111111, 11],
[111111, 2],
]
}, {
type: 'B',
values: [
[111111, 12],
[111111, 12],
[111111, 11],
[111111, 2],
]
}, {
type: 'A',
values: [
[111111, 12],
[111111, 12],
[111111, 11],
[111111, 2],
]
}, {
type: 'B',
values: [
[111111, 12],
[111111, 12],
[111111, 11],
[111111, 2],
]
}, ];
Should convert to
$scope.newArray = [{
type:'A',
values:[
[11111,24],
[11111,24],
[11111,22],
[11111,4],
]
},{
type:'B',
values:[
[11111,24],
[11111,24],
[11111,22],
[11111,4],
]
}];
Here is the Plunker link
for reference.
I would greatly appreciate any assistance provided. Thank you!