Bit confused how this piece of code actually works, mainly because I have never seen a variable being used like this in my first language (Python)
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}}
I am specifically confused about how list is being used with the for-loop. I understand that the first pass through, the list would look like this list = {value: array[i], rest: null};, but how is another list being nested within the first one on the second pass of the for-loop?