It is one of the challenge in the book I fail to understand, or my brain is unable to break it down. Here is the solution function:
function arrayToList(array) {
var list = null;
for (var i = array.length - 1; i >= 0; i--)
list = {value: array[i], rest: list};
return list;
}
console.log(arrayToList([10, 20]));
// → {value: 10, rest: {value: 20, rest: null}}
so we are looping the array inversly so first time list should be:
list = {value:20, rest:{value:20, rest:**mind blows here**}}
can any one help me through this process?