ARTICLE AD BOX
To contextualize the problem a little more, I have been trying to solve this exercise for several days but have not found a concrete solution to it, and the question I have asked myself is how I can access an object to add even more nested objects and so on.
The result I want to find is that based on an argument given to the parameter of my function, which is an array, an object is created with two main values: value, which is the value given as name, which in this case are numbers and they are in the array, and rest, which is a nested object with the same until the values given in the list entered as an argument to the function are finished.
console.log(arrayToList([10, 20])); // → {value: 10, rest: {value: 20, rest: null}} console.log(arrayToList([1,2,3,4,5])); // → {value: 1, rest: {value: 2, rest: {value: 3, rest: {value: 4, rest: {value: 5, rest: null}}}}}The program does not show any particular error but my code definitely does not show what I ask for and only gives me the first part, which would be the first value of the array, and the rest is empty.
My code:
function arrayToList(...valoresList) { debugger; let list; let listaAcceso; for (let index = 0; index < valoresList.length; index++) { if (index == 0) { list = {value: valoresList[0], rest: {}}; continue; }; for (let i = 0; i < index; i++) { listaAcceso = list["rest"] listaAcceso = {value: valoresList[index], rest: {}}; } } return list; } Value return: {value: 1, rest: {}}