Hacker News new | ask | show | jobs
by mhluongo 3264 days ago
Spread syntax should cover linter issues

  Object.entries(obj).map(...).reduce((acc, [prop, value]) => ({...acc, prop:value}))
2 comments

isn't that hideously inefficient? you're making a new object each iteration.
But purity.
it's very unlikely this is going to be the bottleneck in your application
I wouldn't be so quick to write that off as a performance concern. Creating tons of unnecessary objects is JavaScript's equivalent to programming without regard for cache locality at a lower level, due to the way the JITs work.
It's very unlikely you'll get any benefit from doing it the inefficient way either. Does eslint not support "ignore this part" comments?
Yes it does

// eslint-disable-line your-rule-to-ignore

In those cases, I usually use

    Object.assign(acc, { [prop]:value })
While not sure if `[prop]` is better or worse than not creating a new interstitial object.
why not just use acc[prop] = value ?
Assignment does not return `acc`.