Tengo curiosidad por entender como funciona esto, tengo mis dudas:
function arrayToList(array) {
let list = null;
for (let i = array.length - 1; i >= 0; i--) {
list = {value: array[i], rest: list};
}
return list;
¿Qué utilidad tiene esto?
function listToArray(list) {
let array = [];
for (let node = list; node; node = node.rest) {
array.push(node.value);
}
return array;
}
y este:
function prepend(value, list) {
return {value, rest: list};
}
y este también:
function nth(list, n) {
if (!list) return undefined;
else if (n == 0) return list.value;
else return nth(list.rest, n - 1);
}
Tengo una noción de lo que hace, pero estoy confundido.