为了账号安全,请及时绑定邮箱和手机立即绑定

想知道这两层循环中i,和j的变化,里外层循环是怎么走的?

想知道这两层循环中i,和j的变化,里外层循环是怎么走的?

手掌心 2018-09-10 12:06:41
                for (let i = 0; i < this.temp1.length; i++) {                         let found = false;                        for (let j = 0; j < combination_name_list.length; j++) {                            if (combination_name_list[j] == this.temp1[i].name) {                                 found = true;                             }                    if (j == combination_name_list.length - 1 && found == false) {                                this.combination.push({                                    "name": this.temp1[i].name,                                    "rows1": this.temp1[i].rows,                                    "rows2": [],                                    "type": this.temp1[i].type                                 });                             }                         }                     }想知道这两层循环中i,和j的变化,里外层循环是怎么走的,以及这段代码的意思,只能看懂一半!
查看完整描述

1 回答

?
料青山看我应如是

TA贡献1772条经验 获得超7个赞

这个是取差集

var temp1 = [{name:"a"},{name:"d"},{name:"c"}];var combination_name_list = ['a'];

//结果var combination = [{name:"d"},{name:"c"}];

combination_name_list 中存的是 temp1 的 name

就是拿着 temp1 中 第一项 去 combination_name_list 中找 找到了 不操作 ,没找到 将这一项加进 新数组combination 以此类推 第二项 。。。


查看完整回答
反对 回复 2018-09-10
  • 1 回答
  • 0 关注
  • 531 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信