Find the characters in a string which are not duplicated
duplicates, javascript, string
Solution
We can also now clean things up using filter method:
function removeDuplicateCharacters(string) {
return string
.split('')
.filter(function(item, pos, self) {
return self.indexOf(item) == pos;
})
.join('');
}
console.log(removeDuplicateCharacters('baraban'));
Working example:
Problem
I have to make a function in JavaScript that removes all duplicated letters in a string. So far I've been able to do this: If I have the word "anaconda" it shows me as a result "anaconda" when it should show "cod". Here is my code: ``` function find_unique_characters( string ){ var unique=''; for(var i=0; i<string.length; i++){ if(unique.indexOf(string[i])==-1){ unique += string[i]; } } return unique; } console.log(find_unique_characters('baraban')); ```