Created
September 19, 2020 14:14
-
-
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.
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
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