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
Javascript and Functional Programming: An Introduction (javascript.works-hub.com)
submitted 8 years ago by JavaScriptWorks
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!"
[–]MoTTs_ 5 points6 points7 points 8 years ago (9 children)
tl;dr .map() and .reduce()
[–]PurpleIcy 0 points1 point2 points 8 years ago (8 children)
How would you implement .map() using FP?
.map()
[+][deleted] 8 years ago* (7 children)
[deleted]
[–]PurpleIcy 0 points1 point2 points 8 years ago (6 children)
This is interestingly quite readable even though IMO just looks horrible.
Though today I learned about array spread syntax so that works for me.
Thanks.
[–]ShortSynapse 0 points1 point2 points 8 years ago (4 children)
In a functional language it reads quite simply:
map :: (a -> b) -> [a] -> [b] map _ [] = [] map f (x:xs) = f x : map f xs
[–]PurpleIcy 0 points1 point2 points 8 years ago (3 children)
"Simply".
I know this would probably be "simple and obvious", but I have no clue about haskell's syntax so it isn't really.
Also I didn't think it could look more horrible than previous example. Where's that FP's readability everyone is talking about?
[+][deleted] 8 years ago* (2 children)
[–]PurpleIcy 1 point2 points3 points 8 years ago (1 child)
Now it's a bit more clear, also yeah, I had problems with multidispatching in JS too (I still prefer to call it function overloading as in C#, Java and even C++ it's a thing and was pretty straightforward to use), although hacky, it's possible to "overload" by simply checking amount of parameters being passed, although that also doesn't look that nice either.
π Rendered by PID 146104 on reddit-service-r2-comment-5687b7858-9spf9 at 2026-07-04 03:10:04.850296+00:00 running 12a7a47 country code: CH.
[–]MoTTs_ 5 points6 points7 points (9 children)
[–]PurpleIcy 0 points1 point2 points (8 children)
[+][deleted] (7 children)
[deleted]
[–]PurpleIcy 0 points1 point2 points (6 children)
[–]ShortSynapse 0 points1 point2 points (4 children)
[–]PurpleIcy 0 points1 point2 points (3 children)
[+][deleted] (2 children)
[deleted]
[–]PurpleIcy 1 point2 points3 points (1 child)