Horje
js array value that appears odd number of times Code Example
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
check if number appears odd number of times in array javascript
function findOdd(A) {
    let counts = A.reduce((p, n) => (p[n] = ++p[n] || 1, p), {});
    return +Object.keys(counts).find(k => counts[k] % 2) || undefined;
}




Javascript

Related
history.push in nextjs Code Example history.push in nextjs Code Example
jspdf text align center Code Example jspdf text align center Code Example
jqery slectt div in div Code Example jqery slectt div in div Code Example
js today set time Code Example js today set time Code Example
get meta content jquery Code Example get meta content jquery Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
9