function removeDuplicateCharacters(string) {
return string
.split('')
.filter(function(item, pos, self) {
return self.indexOf(item) == pos;
})
.join('');
}
console.log(removeDuplicateCharacters('baraban'));
function removeDuplicate(str, letSingleChar = false) {
let string = str;
for (element of string) {
const re = new RegExp(element, 'g');
if (string.match(re)?.length > 1) {
if (letSingleChar == true) {
string = [...new Set(string.split(''))].join('');
} else
string = string.replace(re, '');
}
}
return string;
}
console.log(removeDuplicate("Hello World", true)) // Helo Wrd
console.log(removeDuplicate("Hello World", false )) // He Wrd
const unrepeated = (str) => [...new Set(str)].join('');
unrepeated("hello"); //➞ "helo"
unrepeated("aaaaabbbbbb"); //➞ "ab"
unrepeated("11112222223333!!!??"); //➞ "123!?"
const names = ['John', 'Paul', 'George', 'Ringo', 'John'];
let unique = [...new Set(names)];
console.log(unique);