Adding Two-dimensional Arrays In Angular/javascript
I am learning basic javascript here, please help, working on adding two-dimensional arrays, where 0th index will be always date and 1st index will be always integer in array, what
Solution 1:
I see that you updated the snippet so here is an example of using map/filter/reduce to get the output you're looking for.
$scope.typeAArray = $scope.mainArray.filter(function (obj) {
return obj.type === 'A';
}).reduce(function (a, b) {
var newObj = {
type: a.type,
values: []
};
a.values.map(function (v, index) {
newObj.values.push(v);
newObj.values[index][1] += b.values[index][1];
});
return newObj;
});
Post a Comment for "Adding Two-dimensional Arrays In Angular/javascript"