Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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;
}
 
PREVIOUS NEXT
Tagged: #check #number #appears #odd #number #times #array #javascript
ADD COMMENT
Topic
Name
1+7 =