What i want it to reverse a list from bottom to top. I used for loop of i--, but i coudn't make it work even by using the built in Reverse() function.
The rules are:
- You cannot use the built-in reverse() function.
- null is non-existent object, you may use an empty object instead if desired.
- Your function should be able to reverse a list of values of any type.
- You must use at least one array to solve the problem.
Original:
var list = {
value: 1,
next: {
value: 2,
next: {
value: 3,
next: null
}
}
};
Reverse it to look like:
var list = {
value: 3,
next: {
value: 2,
next: {
value: 1,
next: null
}
}
};
Example Test Case:
function reverseList(list) {
// return reversedList;
}
Arguments: { value: 1, next: { value: 2, next: { value: 3, next: null } } };
Returns: { value: 3, next: { value: 2, next: { value: 1, next: null } } };
Arguments: { value: "a", next: { value: "b", next: { value: "c", next: null } } };
Returns: { value: "c", next: { value: "b", next: { value: "a", next: null } } };
reverse... since there's absolutely no arrays in that dataReverse a nested Array list Javascriptas Jaromanda already said, there's no array anywhere in that data structure. That's a linked list. where did you get the termnested Array listfrom?4. You must use at least one array to solve the problem.why? that's unnecesary overhead.