Skip to content

Instantly share code, notes, and snippets.

@ethagnawl
Created October 31, 2013 20:49
Show Gist options
  • Save ethagnawl/7256910 to your computer and use it in GitHub Desktop.
Save ethagnawl/7256910 to your computer and use it in GitHub Desktop.
naive first unique letter of string function in JavaScript
function firstNonRepeatingLetter (str) {
var str_arr = str.split('');
return str_arr.filter(function (x) {
return str_arr.indexOf(x) === str_arr.lastIndexOf(x);
})[0];
}
firstNonRepeatingLetter('aardvark') === 'd' // true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment