Garmaine Staff asked 1 year ago

I'm using Underscore and Lodash to group an array by date. So far it's all working nicely and i'm getting an object in which the value for each key is an array of objects, like this:

 {
    "april": [
      {
        "quantity": "200",
        "date": "05/04/2020, 23:43",
        "price": "150",
        "product": "Washing Machine",
        "provider": "LG",
        "total": 30000
      },
      {
        "quantity": "1000",
        "date": "10/04/2020, 00:35",
        "price": "800",
        "product": "Television",
        "provider": "Samsung",
        "total": 800000
      },
      {
        "quantity": "3000",
        "date": "10/04/2020, 18:02",
        "price": "2",
        "product": "Computer",
        "provider": "Sony",
        "total": 600000
      },
      {
        "quantity": "1000",
        "date": "10/04/2020, 18:03",
        "price": "300",
        "product": "Bluetooth Speaker",
        "provider": "Sony",
        "total": 300000
      }
    ],
    "march": [
      {
        "quantity": "400",
        "date": "18/03/2020, 23:47",
        "price": "230",
        "product": "Home Theatre",
        "provider": "Bose",
        "total": 92000
      }
    ],
    "february": [
      {
        "quantity": "550",
        "date": "07/02/2020, 23:52",
        "price": "300",
        "product": "Printer",
        "provider": "Epson",
        "total": 165000
      },
      {
        "quantity": "750",
        "date": "07/02/2020, 23:52",
        "price": "200",
        "product": "Television",
        "provider": "Panasonic",
        "total": 150000
      }
    ]
  } 

I want to know who is the biggest provider by total for each month (for example for April is Sony with two different purchases totalling $900,000), but i've been stuck trying to access and aggregate the data. I know there are tons of similar questions here in Stackoverflow, but surprisingly I haven't been able to find any similar question with this kind of data structure. Any help would be highly appreciated.