MCPcopy Create free account
hub / github.com/marijnh/Eloquent-JavaScript / nth

Function nth

code/solutions/04_3_a_list.js:21–25  ·  view source on GitHub ↗
(list, n)

Source from the content-addressed store, hash-verified

19}
20
21function nth(list, n) {
22 if (!list) return undefined;
23 else if (n == 0) return list.value;
24 else return nth(list.rest, n - 1);
25}
26
27console.log(arrayToList([10, 20]));
28// → {value: 10, rest: {value: 20, rest: null}}

Callers 1

04_3_a_list.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected