Created
June 15, 2018 14:35
-
-
Save adicuco/ab88660b3a6a2724ac74fdab0d037f12 to your computer and use it in GitHub Desktop.
solution for Odd Occurrences in Array Task on Codility
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function solution(A) { | |
var B = []; | |
var max = 0; | |
for (var i = 0; i < A.length; i++) { | |
if (typeof B[A[i]] === "undefined") { | |
B[A[i]] = 0; | |
if (A[i] > max) max = A[i]; | |
} | |
B[A[i]]++; | |
} | |
for (var j = 1; j <= max; j++) { | |
if (typeof B[j] != "undefined") if (B[j] % 2 != 0) return j; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment