链表嵌套对象
Input Should be like this
var ii = {"val":"1","next":{"val":"2","next":{"val":"3","next":{"val":"4","next":{"val":"5","next":null}}}}};
Output should be like [1,2,3,4,5]
最佳答案
Solution
var ii = { "val": "1", "next": { "val": "2", "next": { "val": "3", "next": { "val": "4", "next": { "val": "5", "next": null } } } } };
var arr = [ii.val]
while(ii.next !== null){
ii = ii.next;
arr.push(ii.val)
}
console.log(arr)
关于node.js - 将嵌套对象链表转换为数组 Node js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50304970/