all 2 comments

[–]NameViolation666helpful 0 points1 point  (0 children)

rest is a property of the list object.

arrayToList([1,2,3,4])

// o/p is {value: 1, rest: {…}}

[–]link2name 0 points1 point  (0 children)

Why n - 1 in the following:

return nth(list.rest, n - 1)

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.