Javascript recursion function returning undefined

后端 未结 1 573
野趣味
野趣味 2021-01-16 14:36

I\'m not even certain what the title of this question should be - I\'m not sure what is going wrong at all.

I\'m writing a function that simply loops through a binar

相关标签:
1条回答
  • 2021-01-16 15:14

    Your recursive call have to return the value to the caller

    function searchLeft(node, path) {
        if (typeof node.left == 'undefined') {
            console.log(path);
            return path;
        }
        node = JSON.parse(JSON.stringify(node.left));
        path.push(node.data);
        return searchLeft(node, path); //here return
    }
    
    0 讨论(0)
提交回复
热议问题