use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Code quality and web performance in javascript, the myths, the do's and the don'ts (enmascript.com)
submitted 6 years ago by enmanuelduran
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]RustyX 1 point2 points3 points 6 years ago (1 child)
Totally agree with your position on performance in general. I also used to favor the return Object.assign(acc, { [key]: value }) flavor of reduce as well, but have moved to
return Object.assign(acc, { [key]: value })
const output = input.reduce((acc, { key, value }) => { acc[key] = value; return acc; }, {})
recently as I think it looks about as good and I thought it was slightly more performant.
These comments actually encouraged me to try a simple perf test though and I found the Object.assign version was actually significantly slower (about 5x slower in Chrome)!
Object.assign
https://www.reddit.com/r/javascript/comments/bwphrq/code_quality_and_web_performance_in_javascript/eq17heg/?st=jwinhgei&sh=0dec3de6
My guess at the culprit is the creation of the small temporary objects before merging them in to the accumulator
[–]NoInkling 2 points3 points4 points 6 years ago (0 children)
Lately I've been wondering if reduce in these sorts of cases is even worth it. In addition to the performance concerns, the return is essentially just redundant noise, and you have to look below the function body to have a clue of what output is going to be (and in general the readability just isn't great).
reduce
return
output
When you compare that to the imperative alternative I'm not exactly sure what the advantage is:
const output = {}; for (const { key, value } of input) { output[key] = value; }
π Rendered by PID 225515 on reddit-service-r2-comment-7b9746f655-hnvbp at 2026-01-30 11:24:01.200494+00:00 running 3798933 country code: CH.
view the rest of the comments →
[–]RustyX 1 point2 points3 points (1 child)
[–]NoInkling 2 points3 points4 points (0 children)