Download array by adding items and grouping by month

0

I have an array like this:

"Year:2017,Mes:8,Suma:0"
"Year:2017,Mes:8,Suma:5"
"Year:2017,Mes:8,Suma:5"
"Year:2017,Mes:8,Suma:0"

In what way can I group by month and year, add the data, so that I have another array like this?

"2017-8", "10"

This is what I try:

   let datos = {
    "Year:2017,Mes:8":0,
    "Year:2017,Mes:8":5,
    "Year:2017,Mes:8":5,
    "Year:2017,Mes:8":0,
    };

    console.log( agrupar(datos) ); // 650
    
    function agrupar(datos) {
    
      let sum = 0;
      for (let suma of Object.values(datos)) {
        sum += suma;
      }
    
      return sum;
    }

I know it's not complicated, but I can not do it.

Thanks for the help!

    
asked by Hugo Gonzalez 10.06.2018 в 18:05
source

1 answer

0

This:

let obj = {"a": 1, "b": 2, "a": 3};

it comes to be:

Object {a: 3, b: 2}

As your password always repeats, the last one is 0.

    
answered by 10.06.2018 в 20:03