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);
Array.of(), Array elements are numbered, starting with zero. We can get an element by its number in square brackets: let fruits =� The logical OR (||) operator (logical disjunction) for a set of operands is true if and only if one or more of its operands is true. It is typically used with Boolean (logical) values. When it is, it returns a Boolean value. However, the || operator actually returns the value of one of the specified operands, so if this operator is used with non-Boolean values, it will return a non-Boolean value.
|| 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);
Assuming the arrays always have the same length, use
const OR = (a, b) => a.map((aItem, i) => aItem || b[i]); let a = [0,1,0] let b = [0,0,5] console.log( OR(a, b) );