Skip to content

Instantly share code, notes, and snippets.

@masautt
Created September 6, 2019 04:31
Show Gist options
  • Save masautt/7778c80230db544d0a8e0877b919c6ae to your computer and use it in GitHub Desktop.
Save masautt/7778c80230db544d0a8e0877b919c6ae to your computer and use it in GitHub Desktop.
How to find first non-repeating character in JavaScript?
function firstNonRepeat(string) {
return string.split('').filter(function (character, index, obj) {
return obj.indexOf(character) === obj.lastIndexOf(character);
}).shift();
}
console.log(firstNonRepeat("----Marek-----")); // --> "M"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment