Last active
February 14, 2018 15:02
-
-
Save c7x43t/70c34b74ddb190392ec3c72e882fcd2d to your computer and use it in GitHub Desktop.
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
firstNotRepeatingCharacter = s => { | |
r = {} | |
for (e of s) | |
// ~n = -(n+1) | |
// -~n = n+1 | |
// ~ undefined = -1 | |
// -~undefined = 1 | |
// if character is in hash increment else set to 1 | |
r[e] = -~r[e] | |
for (e in r) | |
// if character occured once return it | |
if (r[e] === 1) | |
return e | |
return '_' | |
} |
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
firstNotRepeatingCharacter=s=>{r={}for(e of s){r[e]=-~r[e]};for(e in r){if(r[e]===1){return e}};return'_'} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment