I was on interview few days ago and at some part of my code like this:
array.reduce((acc, el) => ({
...acc,
[el.id]: [el.value]
}), {})
But after discussion interviewer ask me to rewrite solution to be better performed like this:
array.reduce((acc, el) => {
acc[el.id] = el.value;
return acc;
}, {})
I understand, that copying accumulator every time is not a good solution, but I saw first solution so many times and though that changing accumulator by reference is a bad practice.
So, which code is preferred?