Created
February 23, 2018 21:21
-
-
Save panterozo/791eafb36b5c67044d3acf0dadfbb5c5 to your computer and use it in GitHub Desktop.
Ejercicios Realizados en CodeFights.com
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 firstDuplicate(a) { | |
let length = a.length,result = [], seen = new Set(); | |
let firstOccurance = -1; | |
for (let index = 0; index < length; index++) { | |
let value = a[index]; | |
if (seen.has(value)){ | |
/*Guardo primera ocurrencia y quiebro*/ | |
firstOccurance=value; | |
break; | |
} | |
seen.add(value); | |
} | |
console.log(firstOccurance); | |
return firstOccurance; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment