Skip to content

Instantly share code, notes, and snippets.

@AndrewRayCode
Created December 14, 2016 01:46
Show Gist options
  • Save AndrewRayCode/d9b611c2f7b8ce770c3cf43937e72115 to your computer and use it in GitHub Desktop.
Save AndrewRayCode/d9b611c2f7b8ce770c3cf43937e72115 to your computer and use it in GitHub Desktop.
const newStats = days.map( day => ({ stats: day.statistics.breakdown.byTurnover }) ).reduce(function (pastDay, currentDay) {
const nextStats = currentDay.stats.map(function(stat) {
const oldSold = pastDay.stats.find(function (old) {
return old.name === stat.name;
});
const newSold = stat.sold + oldSold.sold;
stat.sold = newSold;
return stat;
});
return {
stats: nextStats,
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment