为什么这段代码运行错误

这段代码有什么问题吗?为甚么结果不是预期的? 在js控制台是可以的
山东省
浏览 277
收藏
2
分享
2 +1
4
+1
全部评论 4
 
我找到原因了: 内置的filter不好用,自己写了个forEach就可以了 let rows = [1, 2, 3, 4, 5, 6, 7, 8] let a = rand() console.log("a: ", a) let b = rand() console.log("b: ", b) //let c = a.filter(item => b.indexOf(item) > -1) let c = intersection(a, b) console.log("intersection of a and b: ", c) function rand() { return rows.filter(() => Math.random() > 0.5) } function intersection(a, b) { let c = [] a.forEach(item => { if (b.indexOf(item) > -1) { c.push(item) } }) return c }
· 山东省
回复
 
黑化新路

WPS函数专家

不知道左图上面还有什么内容 ,可能是其他代码影响了?
· 重庆
回复
代码多了发布上来,有办法可以直接给你吗
· 山东省
回复