I am trying to complete the following challenge...
Given an array of integers, find the one that appears an odd number of times.
There will always be only one integer that appears an odd number of times.
This is my current solution, that does not work. I believe there is a logic error somewhere but I am unsure. Any alternative ways to approach the solution that are beginner friendly are welcome also.
I am fairly new to JavaScript so please go easy!
function findOdd(A) {
for (let i = 0; i < A.length; i++) {
let arrayCount = [];
let num = A[i]
for (let x = 0; x < A.length; x++)
if (A[i] === num) {
arrayCount.push(num);
//console.log(arrayCount);
i++;
}
if (arrayCount.length % 2 !== 0) {
return num;
}
}
}
const checkList = [1, 1, 2, 2, 3, 4, 4];
console.log(findOdd(checkList));