Skip to content

Instantly share code, notes, and snippets.

@mplungjan
Created January 5, 2013 10:18
Show Gist options
  • Save mplungjan/4460865 to your computer and use it in GitHub Desktop.
Save mplungjan/4460865 to your computer and use it in GitHub Desktop.
Find unique characters in string - demo http://jsfiddle.net/mplungjan/YUXVF/
function find_unique_characters(string){
unique=[];
while(string.length>0){
var char = string.charAt(0);
var re = new RegExp(char,"g");
console.log(re,char,string.match(re))
if (string.match(re).length===1) unique.push(char);
string=string.replace(re,"");
}
return unique.join("");
}
console.log(find_unique_characters('baraban'));
console.log(find_unique_characters('anaconda'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment