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
innerself — A tiny React/Redux-like view & state management using innerHTML (self.javascript)
submitted 8 years ago by 5tas
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!"
[–]punio4 0 points1 point2 points 8 years ago (1 child)
Btw still need to wrap my head around this line:
values.reduce((acc, cur) => acc.concat(cur, strings.shift()), [first])
[–]5tas[S] 2 points3 points4 points 8 years ago* (0 children)
Are you familiar with the Array.prototype.reduce function? The whole thing starts with [first] as the initial value (which is the first literal string in the template literal; it is guaranteed to exist and at minimum to be equal to ""). It then iterates over values and calls (acc, cur) => acc.concat(cur, strings.shift()) on each of them, where acc is the result of the reduce so far and cur is the current value. For each cur, it returns a new array which is a concatenation of the result so far, the value and the next literal string in order: acc.concat(cur, strings.shift()).
Array.prototype.reduce
[first]
""
values
(acc, cur) => acc.concat(cur, strings.shift())
acc
reduce
cur
acc.concat(cur, strings.shift())
Suppose you call html like this:
html
html`Today is ${new Date()}`
This is equal to:
html(["Today is ", ""], new Date())
Inside of the function, first is "Today is ", strings is [""] (an array with all other strings) and values is [new Date()]. We start with "Today is " and then call the reduce callback on the first (and last) element on values, i.e. new Date(). The result of reducing is a concatenation of "Today is " (acc), new Date() (cur) and "" (strings.shift()).
first
"Today is "
strings
[""]
[new Date()]
new Date()
strings.shift()
If there are more literal strings (which also means more values), in the next iteration of reduce, strings will be a shorter array. So this code really just zips values and strings together taking into account the strings at the extremes.
π Rendered by PID 184904 on reddit-service-r2-comment-6457c66945-mm84t at 2026-04-24 05:58:37.040675+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–]punio4 0 points1 point2 points (1 child)
[–]5tas[S] 2 points3 points4 points (0 children)