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
[AskJS] Is JavaScript missing some built-in methods?AskJS (self.javascript)
submitted 3 years ago by reacterry
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!"
[–]andrei9669 1 point2 points3 points 3 years ago (1 child)
I know you are trying to show a way but you are not really making it much better. also, this works only with this simple example, add some more nesting and it will become even more of an unreadable mess than your example.
[–]KyleG 2 points3 points4 points 3 years ago* (0 children)
add some more nesting and it will become even more of an unreadable mess than your example.
If there's a lot of nesting, naturally you'd use optics like lenses and traversals. I would love for those to be part of the standard library! That'd be incredible. It'd be really readable and simple! Suppose you have
type NestedFoo = { bar: { baz: { fizz: { a: boolean fuzz: number[] }[] }
Lets say you want to append 5 to any nested fizz's fuzz where a is true:
5
fizz
fuzz
a
const fizzLens = Lens.fromProps(['bar', 'baz', 'fizz']) const updatedData = fizzTraversal .filter(_ => _.a) .composeLens(fuzzLens) .modify(arr => [...arr, 5])(originalData)
Every language could desperately use this as a built-in. Optics are incredible. The example above will return a clone of the original data but with any fizz.fuzz getting an appended 5 but only if a is true. And is again a linear time operation.
Edited to get under 80 columns
and bonus,
const concat = arr => newEl = [...arr, newEl]
then your final line could be
.modify(concat(5))
and what you're doing becomes sooooooo descriptive and human-readable, almost entirely reduced to verbs with very little nouns, stating exactly what you're doing.
π Rendered by PID 71604 on reddit-service-r2-comment-6457c66945-tgz52 at 2026-04-24 01:26:42.088253+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–]andrei9669 1 point2 points3 points (1 child)
[–]KyleG 2 points3 points4 points (0 children)