Que fait ce code
const groupBy = (arr, key) =>
arr.reduce((acc, i) => {
(acc[i[key]] = acc[i[key]] || [] ).push(i);
return acc;
}, {});
const data = [
{
nom: "coka",
cat: "Boisson",
prix: 4,
},
{
nom: "pepsi",
cat: "Boisson",
prix: 9,
},
{
nom: "farine",
cat: "Epicerie",
prix: 4,
},
];
const cat = groupBy(data,"cat")
, prix = groupBy(data,"prix");
en action : pythontutor