DEV Community

Discussion on: Refactoring old code

Collapse
 
lexlohr profile image
Alex Lohr

Maybe use the spread operator instead:

const newOutput = Object.entries(data)
  .map((item, index) => [...item, colors[index] || '#fff'])
  .sort((a, b) => b[1] - a[1]);
Enter fullscreen mode Exit fullscreen mode

I think it makes more clear that you are not changing the item itself.

Collapse
 
dailydevtips1 profile image
Chris Bongers

Hey Alex,

Great addition! 100% makes sense for readability!
Refactor on the refactor 👀