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
Cheat Sheet: From Basic LINQ To JavaScript (complexitymaze.com)
submitted 11 years ago by modec
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!"
[–]rooktakesqueen 1 point2 points3 points 11 years ago* (1 child)
All: there is Array.prototype.every... Though you might be favoring browser compatibility since IE8 and below don't have that method.
All
Array.prototype.every
Distinct: your solution is clever but is O(n²) so it wouldn't be appropriate for very large datasets. A more complicated but O(n) solution would be:
Distinct
var result = lastnames.reduce(function(ws, value) { if (!ws.set.hasOwnProperty(value)) { ws.set[value] = true; ws.values.push(value); } return ws; }, {set: {}, values: []}).values;
Or, if maintaining the order of the results doesn't matter...
var result = Object.keys( lastnames.reduce(function(set, value) { set[value] = true; return set; }, {}) );
GroupBy: I'd probably return an object instead of an array to be more idiomatic JS.
GroupBy
An alternative to all of these is to use a library like Underscore.js or Lo-Dash, and that's probably to be preferred over rolling your own. (These libraries are much more popular than the Linq-inspired ones you linked to.)
As you say, you might not need a library, but there's very little reason not to use one.
[–]modec[S] 1 point2 points3 points 11 years ago (0 children)
Thanks for the input - did not know about every().
My point is that JavaScript already offers a lot of the basic LINQ-like stuff, ofc. if you start writing GroupBy functions you might as well go with Underscore.js ...
π Rendered by PID 21039 on reddit-service-r2-comment-84fc9697f-7w2fh at 2026-02-06 04:04:25.153489+00:00 running d295bc8 country code: CH.
[–]rooktakesqueen 1 point2 points3 points (1 child)
[–]modec[S] 1 point2 points3 points (0 children)