Skip to content

Instantly share code, notes, and snippets.

@c7x43t
Last active February 14, 2018 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save c7x43t/70c34b74ddb190392ec3c72e882fcd2d to your computer and use it in GitHub Desktop.
Save c7x43t/70c34b74ddb190392ec3c72e882fcd2d to your computer and use it in GitHub Desktop.
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 '_'
}
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