在JavaScript中逻辑与两个布尔数组?

达赫施泰因

在ES6中将两个布尔数组相加的函数式优雅解决方案是什么?

const a1 = [true, false, false]
const a2 = [true, true, false]

应导致:

[true, false, false]
或Drori

使用可以使用Array#map迭代第一个数组,并使用索引(回调中的第二个参数)获取第二个数组的值:

const a1 = [true, false, false]
const a2 = [true, true, false]

const result = a1.map((b, i) => b && a2[i]);

console.log(result);

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章