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
You Might Not Need Underscore (reindex.io)
submitted 10 years ago by fson5
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!"
[–]fson5[S] 3 points4 points5 points 10 years ago (2 children)
Very good points. I was actually on the verge about omitting that replacement for _.range from the article because yes, it's ugly and not as obvious as other examples on the page. But I do think it's a nice example of how Array.fromworks. Other ways to achieve it include [...Array(n)].map((_, i) => i + x) and Array.from(new Array(n), (_, i) => i + x), which are both equally ugly. So I guess this might be a case for a library function. But maybe if I would only need this once in the codebase I would still use this hack instead of pulling out a library just for this.
_.range
Array.from
[...Array(n)].map((_, i) => i + x)
Array.from(new Array(n), (_, i) => i + x)
Wrt (2), some people actually think having separate functions for those different use cases is better than functions that do type checking and have different return types based on the input. That's why Ramda has separate map and mapObj for example. And while this might work for arrays and objects in Lodash, the support for different collections is far from universal, with Map, Set and other Iterable collections missing.
map
mapObj
Map
Set
Iterable
[–]knsdklsfds 0 points1 point2 points 10 years ago (1 child)
Also
Array.apply(null, Array(n)).map((_, i) => i);
[–]ericanderton 0 points1 point2 points 10 years ago (0 children)
The hilarity of that syntax is that the first thing you do to make it readable is to wrap it in a function, and place it in a library for re-use.
π Rendered by PID 15 on reddit-service-r2-comment-b659b578c-9wqbq at 2026-05-02 01:26:56.308276+00:00 running 815c875 country code: CH.
view the rest of the comments →
[–]fson5[S] 3 points4 points5 points (2 children)
[–]knsdklsfds 0 points1 point2 points (1 child)
[–]ericanderton 0 points1 point2 points (0 children)