What would be a nice elegant functional solution for anding two boolean arrays in ES6?
const a1 = [true, false, false]
const a2 = [true, true, false]
should result in:
[true, false, false]
Use can use Array#map to iterate the 1st array, and get the value of the 2nd array using the index (the 2nd param in the callback):
const a1 = [true, false, false]
const a2 = [true, true, false]
const result = a1.map((b, i) => b && a2[i]);
console.log(result);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With