how to find the odd numbers in an array javascript code example
Example 1: js array value that appears odd number of times
// Find the odd int
function findOdd(A) {
return A.reduce((a, b) => a ^ b);
}
console.log(findOdd([20,1,-1,2,-2,3,3,5,5,1,2,4,20,4,-1,-2,5], 5)); // 5
console.log(findOdd([1,1,2,-2,5,2,4,4,-1,-2,5], -1)); // -1
console.log(findOdd([20,1,1,2,2,3,3,5,5,4,20,4,5], 5)); // 5
Example 2: find even numbers in an array javascript
arr.filter(num => num % 2)