remove repeated characters from a string in javascript
function removeDuplicateCharacters(string) {
return string
.split('')
.filter(function(item, pos, self) {
return self.indexOf(item) == pos;
})
.join('');
}
console.log(removeDuplicateCharacters('baraban'));
3.8
5
const arr = [1, 2, [3, 4]];
// To flat single level array
arr.flat();
// is equivalent to
arr.reduce((acc, val) => acc.concat(val), []);
// [1, 2, 3, 4]
// or with decomposition syntax
const flattened = arr => [].concat(...arr);
Thank you!
5
0
3.7
10
const unrepeated = (str) => [...new Set(str)].join('');
unrepeated("hello"); //➞ "helo"
unrepeated("aaaaabbbbbb"); //➞ "ab"
unrepeated("11112222223333!!!??"); //➞ "123!?"
Thank you!
10
0
0
0
let myString = "EElllzzzzzzzeroo";<br/>let nam = myString<br/> .split("")<br/> .filter(function (ele, index, array) {<br/> return array.indexOf(ele) == index;<br/> })<br/> .join("");<br/><br/><br/>console.log(nam);
Thank you!
0
0
Are there any code examples left?
New code examples in category Javascript