I tried to find an answer to this question, please forgive me if I am just too stupid to find it. I am sorry if that's the case. But I have this loop and I have no idea why it does what it does. This is an exercise from the book "Eloquent JavaScript" by Marjin Haverbeke (Page 89, if anyone's interested)
My question is how the variable "node" works as a second statement.
Any explanation much appreciated!
Thanks, Ben
list = { value: 'one', rest: { value: 'two', rest: { value: 'three', rest: null }}};
function listToArray(list) {
let array = [];
for (let node = list; node ; node = node.rest) {
array.push(node.value);
}
return array;
}
console.log(listToArray(list));
Output: [ 'one', 'two', 'three' ]