Created
February 23, 2018 21:22
-
-
Save panterozo/6c98b5661e7a30d633707231e1646cbf 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 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