I went through a simple problem, but its solution got me confused.
function modifyArray(nums) {
// i & 1 will be 1, or true, if 'i' is odd
return nums.map(i => (i & 1) ? i * 3 : i * 2);
}
console.log(modifyArray([0, 1, 2, 3, 4, 5]));
In the above code,(i&1) returns true or 1 if i is an odd number.
How does this work, can anyone please explain?