Skip to content

Instantly share code, notes, and snippets.

@panterozo
Created February 23, 2018 21:22
Show Gist options
  • Save panterozo/6c98b5661e7a30d633707231e1646cbf to your computer and use it in GitHub Desktop.
Save panterozo/6c98b5661e7a30d633707231e1646cbf to your computer and use it in GitHub Desktop.
Ejercicios Realizados en CodeFights.com
function firstNotRepeatingCharacter(s) {
/*Se define un array al cual se irá sacando información*/
let length = s.length,result = [], seen = new Set(), notSeen = new Set();
let notOcurrance = "_";
for (let index = 0; index < length; index++) {
let value = s[index];
if (seen.has(value)){
notSeen.delete(value);
}else{
notSeen.add(value);
}
seen.add(value);
}
if (notSeen.size > 0) {
/*Se obtiene el valor del primer Set*/
var it = notSeen.values();
var first = it.next();
notOcurrance = first.value;
}
console.log(notOcurrance);
return notOcurrance;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment