Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function nth(list, n) {
- if (!list)
- return undefined;
- else if (n == 0)
- return list.value;
- else
- return nth(list.rest, n - 1);
- }
- undefined
- someList = {value: 5 rest:{value: 10, rest:{value: 20, rest: null}}}
- nth(someList, 2); //=> 20
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement