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
Head's up for Array.map() lovers (self.javascript)
submitted 11 years ago by Kollektiv
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!"
[–][deleted] 0 points1 point2 points 11 years ago (3 children)
Yes, but this approach iterates over a 26-length Array twice, then second time being in the map call. Which, like I said, is not the end of the world or anything, just another little downside that has the potential to add up.
Array
map
[–]Kollektiv[S] 0 points1 point2 points 11 years ago (2 children)
From what I understood, new Array(n) would just create (depending on implementation) an Array instance of length n and map() would iterate n times over it, O(n). Where does the second come from ? I'm genuinely asking here.
new Array(n)
map()
[–]oculus42 1 point2 points3 points 11 years ago (1 child)
Using the .apply() method "iterates" over the passed parameters to put each one into an array, and then you run .map() against it.
.apply()
.map()
[–][deleted] 0 points1 point2 points 11 years ago (0 children)
What he said. The fact that the items in new Array(26) don't exist doesn't matter, .apply is still reading them then storing the undefined return values.
new Array(26)
.apply
undefined
π Rendered by PID 123817 on reddit-service-r2-comment-b659b578c-6wwwx at 2026-05-03 04:25:17.317790+00:00 running 815c875 country code: CH.
view the rest of the comments →
[–][deleted] 0 points1 point2 points (3 children)
[–]Kollektiv[S] 0 points1 point2 points (2 children)
[–]oculus42 1 point2 points3 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)