Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Your code here.
- arrayToList = arr => {
- doStuff = (arr, obj) => {
- if(arr.length){
- console.log('arr ',arr)
- obj.value = arr[0];
- obj.rest = {};
- arr.shift();
- return (doStuff(arr, obj.rest));
- }else{
- console.log('else ', obj);
- obj.rest = {value : arr[0], rest : null}
- return obj;
- }
- }
- obj = {};
- doStuff(arr, obj);
- return obj;
- }
- console.log(arrayToList([10, 20]));
- // → {value: 10, rest: {value: 20, rest: null}}
- //console.log(listToArray(arrayToList([10, 20, 30])));
- // → [10, 20, 30]
- //console.log(prepend(10, prepend(20, null)));
- // → {value: 10, rest: {value: 20, rest: null}}
- //console.log(nth(arrayToList([10, 20, 30]), 1));
- // → 20
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement