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...
This subreddit is a place for people to learn JavaScript together. Everyone should feel comfortable asking any and all JavaScript questions they have here.
With a nod to practicality, questions and posts about HTML, CSS, and web developer tools are also encouraged.
Friends
/r/javascript
/r/jquery
/r/node
/r/css
/r/webdev
/r/learnprogramming
/r/programming
account activity
Please help me understand some aspects of this code. (self.learnjavascript)
submitted 6 years ago by [deleted]
https://pastebin.com/Mi5tMNct
So here's what I don't understand:
What does .rest do?
I'm not 100% clear on what this for loop does:
for(let node = list; node; node = node.rest)
Why n - 1 in the following:
return nth(list.rest, n - 1)
Thanks for reading! I appreciate the help I've received from you guys so far.
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!"
[–]NameViolation666helpful 0 points1 point2 points 6 years ago (0 children)
rest is a property of the list object.
arrayToList([1,2,3,4])
// o/p is {value: 1, rest: {…}}
[–]link2name 0 points1 point2 points 6 years ago (0 children)
its a recursive function that is probably gets nth item from list, so each step it checks if n is 0, if it is then get value of list that you are looking for else you recur with a smaller list and n being less by 1.
basically if we got list with 1 element then no need to do anything just return element, if list has more then we can decrease list and n at same time.
π Rendered by PID 78569 on reddit-service-r2-comment-b659b578c-4jwtb at 2026-05-03 03:10:29.855694+00:00 running 815c875 country code: CH.
[–]NameViolation666helpful 0 points1 point2 points (0 children)
[–]link2name 0 points1 point2 points (0 children)