It seems as though the examples for _.reduce (or the equivalent native function) are very simplistic. Could someone provide an example of using this function to sum and then rank/sort an array of objects? For example, if my array contains --
[{ name: 'John', store: 23, revenue: 300.00 },
{ name: 'John', store: 23, revenue: 600.00 },
{ name: 'Kerry', store: 23, revenue: 100.00 },
{ name: 'Kerry', store: 23, revenue: 200.00 },
{ name: 'Lars', store: 24, revenue: 600.00 },
{ name: 'Lars', store: 24, revenue: 800.00 },
{ name: 'Lars', store: 24, revenue: 1000.00 },
{ name: 'Indira', store: 24, revenue: 1800.00 },
{ name: 'Indira', store: 24, revenue: 2800.00 },
{ name: 'Indira', store: 24, revenue: 3800.00 },
{ name: 'Jacinta', store: 24, revenue: 300.00 }]
And I want the output to be as follows:
[{store: 23, rank: 1, name: 'John', revenue: 900.00},
{store: 23, rank: 2, name: 'Kerry', revenue: 300.00},
{store: 24, rank: 1, name: 'Indira', revenue: 8400.00},
{store: 24, rank: 2, name: 'Lars', revenue: 2400.00},
{store: 24, rank: 3, name: 'Jacinta', revenue: 300.00}]
What's the best way to go about this?