Created
October 1, 2017 19:36
-
-
Save johndavedecano/a5bd52af4792306d53695fbbf9d36f39 to your computer and use it in GitHub Desktop.
EXAMS - ODD OCCURENCES
This file contains hidden or 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) { | |
// write your code in JavaScript (Node.js 4.0.0) | |
var B = []; | |
for(var i = 0; i < A.length; i++){ | |
var index = B.indexOf(A[i]); | |
if(index > -1) B.splice(index, 1); | |
else B.push(A[i]); | |
} | |
return B[0]; | |
} | |
function solution(A) { | |
// write your code in JavaScript (Node.js 4.0.0) | |
var odd; | |
for(var i = 0; i < A.length; i++){ | |
odd ^= A[i]; // exclusive or | |
} | |
return odd; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment