学习不会让人秃头 2022-09-08 21:30 采纳率: 50%
浏览 168
已结题

js数组添加有长度但是没有数据

js 有长度但是没有数据,考虑到是可能是异步问题或者深拷贝,但是不知道怎么修改
    let candidates = [2, 3, 6, 7]
    let target = 7
    let path = []
    let sum = 0
    let startindex = 0
    var res = []
    function backTracing(candidates, target, sum, startindex) {
        if (sum > target) {
            return
        }
        if (sum === target) {
            res.push(path)
            console.log(path);
            return res
        }

        for (let i = startindex; i < candidates.length; i++) {
            path.push(candidates[i])
            sum += candidates[i]
            // console.log(sum);
            backTracing(candidates, target, sum, i)
            sum -= candidates[i]
            path.pop()
        }

        return res
    }


    abc = backTracing(candidates, target, sum, startindex)

        console.log(abc);let candidates = [2, 3, 6, 7]
    let target = 7
    let path = []
    let sum = 0
    let startindex = 0
    var res = []
    function backTracing(candidates, target, sum, startindex) {
        if (sum > target) {
            return
        }
        if (sum === target) {
            res.push(path)
            console.log(path);
            return res
        }

        for (let i = startindex; i < candidates.length; i++) {
            path.push(candidates[i])
            sum += candidates[i]
            // console.log(sum);
            backTracing(candidates, target, sum, i)
            sum -= candidates[i]
            path.pop()
        }

        return res
    }


    abc = backTracing(candidates, target, sum, startindex)

        console.log(abc);
运行结果及报错内容

img

我想要达到的结果

img

  • 写回答

1条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      问题事件

      • 系统已结题 9月21日
      • 已采纳回答 9月13日
      • 创建了问题 9月8日

      悬赏问题

      • ¥15 结构体数组文件读取问题
      • ¥15 写c++代码,第7题说一下使用的计算方法
      • ¥15 postman接口自动化测试报告实践总结
      • ¥15 有关c++的问题,利用相关知识
      • ¥15 求香农编码和解码的matlab代码
      • ¥20 ROS中的TEB局部规划问题
      • ¥20 关于#matlab#的问题:要求测出上面图片中所有同心圆的半径
      • ¥20 epanet软件运行问题
      • ¥15 Python 文件读取
      • ¥60 dpabi进行Alff计算时脑池有干扰信号