Skip to content

Commit

Permalink
Find the odd int - Coding Dojo
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeltomasik committed Jan 21, 2019
1 parent 0d7ba5a commit 4a1953f
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions findTheOddInt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// https://www.codewars.com/kata/find-the-odd-int/

// Description:
// Given an array, find the int that appears an odd number of times.
// There will always be only one integer that appears an odd number of times.

function findOdd(numberArr) {
const numberDict = {};
for (let i = 0; i < numberArr.length; i++) {
const number = numberArr[i];
numberDict[number] = numberDict[number] ? (numberDict[number] + 1) : 1;
}
let oddNumber = 0;
for (let key in numberDict) {
oddNumber = numberDict[key] % 2 ? key : oddNumber;
};

return parseInt(oddNumber);
}

0 comments on commit 4a1953f

Please sign in to comment.