Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save hassan-maavan/779aeb33c2bda55d87d3093e5b668ec0 to your computer and use it in GitHub Desktop.
Save hassan-maavan/779aeb33c2bda55d87d3093e5b668ec0 to your computer and use it in GitHub Desktop.
Write a function that finds the first element that appers an even number of times in an unsorted array.
Write a function that finds the first element that appers an even number of times in an unsorted array.
// input: [5,3,5,1,5,1,3]
// output: 3
let arr = [5,3,5,1,5,1,3];
let value = '';
for(let i = 0; i < arr.length; i++){
let val = arr[i];
if(arr.filter((v) => v === val).length % 2 == 0){
value = val;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment