2 ms·
Indeed. A pure function should not depend on and / or mutate external variables. I'd do it like this (yay for one-ish-liners!): const playersByCountry = foo
by bestest 9y ago
Indeed. A pure function should not depend on and / or mutate external variables.
I'd do it like this (yay for one-ish-liners!):
const playersByCountry = footballPlayers.reduce((acc, player) => {
return {...acc, [player.country]: [...(acc[player.country] || []), player]};
}, {});