Created
January 5, 2013 10:18
-
-
Save mplungjan/4460865 to your computer and use it in GitHub Desktop.
Find unique characters in string - demo http://jsfiddle.net/mplungjan/YUXVF/
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
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