June 15th, 2024
What's missing in this code?
const fruits = [
{ name: 'pineapple🍍', color: '🟡' },
{ name: 'apple🍎', color: '🔴' },
{ name: 'banana🍌', color: '🟡' },
{ name: 'strawberry🍓', color: '🔴' },
];
const groupFn =
;
const fruitBaskets = fruits.reduce(
(grouped, obj) => (
...grouped,
[groupFn(obj)]: [
, obj],
}),
{}
);
console.log(fruitBaskets);
// { '🟡': [ { name: 'pineapple🍍', color: '🟡' }, ... ] }
Type or select from these options