5 ms·
Your linter will also complain about modifying newObj within the reducer.
by nathancahill 9y ago
Your linter will also complain about modifying newObj within the reducer.
- mhluongo 9y agoSpread syntax should cover linter issues Object.entries(obj).map(...).reduce((acc, [prop, value]) => ({...acc, prop:value}))
- Rotten194 9y agoisn't that hideously inefficient? you're making a new object each iteration.
- Touche 9y agoBut purity.
- djfm 9y agoit's very unlikely this is going to be the bottleneck in your application
- mintplant 9y agoI 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.
- Touche 9y agoIt's very unlikely you'll get any benefit from doing it the inefficient way either. Does eslint not support "ignore this part" comments?
- Prefinem 9y agoYes it does // eslint-disable-line your-rule-to-ignore
- tracker1 9y agoIn 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.
- v413 9y agowhy not just use acc[prop] = value ?
- elmigranto 9y agoAssignment does not return `acc`.
- paulddraper 9y agoWhich a problem with using linters, not with programming.
- nawitus 9y agoWhich linter rule is that?
- mirekrusin 9y agoThe one that doesn't like modifying function arguments?
- nawitus 9y agoUsually that only disallows reassignment of function arguments. For example, eslint's no-param-reassign rule by default allows modifying the properties of the function argument. However, the "props" parameter for this rule can disallow even the modification of properties of a function's argument.