Advertisement
Guest User

t4nk147

a guest
Feb 12th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function nth(list, n) {
  2.   if (!list)
  3.     return undefined;
  4.   else if (n == 0)
  5.     return list.value;
  6.   else
  7.     return nth(list.rest, n - 1);
  8.   }
  9. undefined
  10.  
  11. someList = {value: 5 rest:{value: 10, rest:{value: 20, rest: null}}}
  12.  
  13. nth(someList, 2);  //=> 20
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement