hi if someone can explain how this works and returns what it does I would be much appreciative. This part confuses me, I dont understand why we would set something equal to cur
= cur;
return acc;
let users = [
{ id: "john", name: "John Smith", age: 20 },
{ id: "ann", name: "Ann Smith", age: 24 },
{ id: "pete", name: "Pete Peterson", age: 31 },
];
let usersById = groupById(users);
function groupById(array) {
return array.reduce((acc, cur) => {
acc[cur.id] = cur;
return acc;
}, {});
}
console.log(usersById);