Skip to content

Instantly share code, notes, and snippets.

@panterozo
Created February 23, 2018 21:21
Show Gist options
  • Save panterozo/791eafb36b5c67044d3acf0dadfbb5c5 to your computer and use it in GitHub Desktop.
Save panterozo/791eafb36b5c67044d3acf0dadfbb5c5 to your computer and use it in GitHub Desktop.
Ejercicios Realizados en CodeFights.com
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