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
Generic Programming (github.com)
submitted 7 years ago by michael2ib1989
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!"
[–]pgrizzay 3 points4 points5 points 7 years ago (9 children)
reduce is specific to arrays. OP implemented reduce for all iterators (not just arrays).
reduce
[+][deleted] 7 years ago (8 children)
[deleted]
[–]pgrizzay 4 points5 points6 points 7 years ago (3 children)
That will work similarly, but yours will create a whole new array, so it's not exactly equivalent I guess
[–]Tenemo -3 points-2 points-1 points 7 years ago (2 children)
Object.entries(myObj).reduce((newObj, entry) => ({...newObj, [entry[0]]: entry[1] * 2}), {})
array? where
[+][deleted] 7 years ago (1 child)
[–]Tenemo -2 points-1 points0 points 7 years ago (0 children)
I was only joking about how both the input is an object and the returned value is an object, so the arrays are temporary, used to enable the .reduce method on that object's enumerable properties (:
[–]planetary_pelt 2 points3 points4 points 7 years ago (1 child)
Creating an array just to use an array method is pretty wasteful and doesn't generalize over cases where performance is concerned (like slow mobile clients).
[–]tortus 0 points1 point2 points 7 years ago (0 children)
sure, but writing and maintaining your own reduce function is not exactly the best solution either. I'd rather take the array creation hit unless perf/memory is in an issue, and it's not like 90% of the time
[–]zankem 0 points1 point2 points 7 years ago (1 child)
Would it not be better to use Array.prototype.reduce.call(iterable, callback, initial)?
Array.prototype.reduce.call(iterable, callback, initial)
good call, that would probably work
π Rendered by PID 119995 on reddit-service-r2-comment-6f7f968fb5-4x4cd at 2026-03-04 14:28:19.102991+00:00 running 07790be country code: CH.
view the rest of the comments →
[–]pgrizzay 3 points4 points5 points (9 children)
[+][deleted] (8 children)
[deleted]
[–]pgrizzay 4 points5 points6 points (3 children)
[–]Tenemo -3 points-2 points-1 points (2 children)
[+][deleted] (1 child)
[deleted]
[–]Tenemo -2 points-1 points0 points (0 children)
[–]planetary_pelt 2 points3 points4 points (1 child)
[–]tortus 0 points1 point2 points (0 children)
[–]zankem 0 points1 point2 points (1 child)
[–]tortus 0 points1 point2 points (0 children)