let a = [0,1,0] let b = [0,0,5]
OR(a, b) [0,1,5]
What would be an efficient and idiomatic way to implement
You could reduce the wanted arrays by taking a mapping and an
const or = (a, b) => a || b, mapped = fn => (a, b) => a.map((v, i) => fn(v, b[i])); var a = [0, 1, 0], b = [0, 0, 5], c = [a, b].reduce(mapped(or)); console.log(c);
|| operator in combination with
map method by passing a callback function as argument.
let a = [0,1,0] let b = [0,0,5] let c = a.map((item, index) => item || b[index]); console.log(c);