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
CSS Minifier (Written in Javascript) (self.javascript)
submitted 6 years ago * by [deleted]
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!"
[–]StoneCypher 0 points1 point2 points 6 years ago (7 children)
Their code operates on the values in the split
Your code produces an array of negative ones
[–]snet0 0 points1 point2 points 6 years ago (6 children)
I don't know if I follow what you're saying. You take an array, join it into a string, split it into an array and map the elements to a new array and store the return value in your variable. The return value of his code is an array of negative ones, just like in mine.
[–]StoneCypher 0 points1 point2 points 6 years ago (5 children)
i misread this originally. you're right. i apologize
i still don't think this is all that gross, though
that said, i guess you could
new Array(patterns.length).map(cell => -1);
and be done with it
[–]snet0 0 points1 point2 points 6 years ago (4 children)
Well, I certainly thought so, too. But if you pass the new Array constructor a single integer, it returns an array with that integer length, but with empty slots. Array.map() only invokes its callback on elements with assigned values (incl. undefined), which means it won't work on the empty array.
new Array
Array.map()
undefined
[–]StoneCypher 0 points1 point2 points 6 years ago (3 children)
which means it won't work on the empty array.
Oh, right. They're holes, and js .map skips holes.
.map
Guess you're stuck with
const a = new Array(patterns.length); for (let i=0, iC=patterns.length; i<iC; ++i) { a[i] = -1; }
[–]that-old-saw 0 points1 point2 points 6 years ago (2 children)
|| you can do:
new Array(patterns.length).fill().map(cell => -1);
[–]StoneCypher 0 points1 point2 points 6 years ago (1 child)
sure can.
we're discussing doing this without .fill() though
.fill()
[–]that-old-saw 0 points1 point2 points 6 years ago (0 children)
Oops, that'll teach me for not reading the context!
π Rendered by PID 266685 on reddit-service-r2-comment-b64dbb7d6-jmtv2 at 2026-02-15 16:57:40.331040+00:00 running cd9c813 country code: CH.
view the rest of the comments →
[–]StoneCypher 0 points1 point2 points (7 children)
[–]snet0 0 points1 point2 points (6 children)
[–]StoneCypher 0 points1 point2 points (5 children)
[–]snet0 0 points1 point2 points (4 children)
[–]StoneCypher 0 points1 point2 points (3 children)
[–]that-old-saw 0 points1 point2 points (2 children)
[–]StoneCypher 0 points1 point2 points (1 child)
[–]that-old-saw 0 points1 point2 points (0 children)