Skip to content

Instantly share code, notes, and snippets.

@johndavedecano
Created October 1, 2017 19:36
Show Gist options
  • Save johndavedecano/a5bd52af4792306d53695fbbf9d36f39 to your computer and use it in GitHub Desktop.
Save johndavedecano/a5bd52af4792306d53695fbbf9d36f39 to your computer and use it in GitHub Desktop.
EXAMS - ODD OCCURENCES
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