replace repeated characters in a string javascript code example
Example 1: duplicate characters in a string javascript
const text = 'abcda'.split('')
text.some( (v, i, a) => {
return a.lastIndexOf(v) !== i
}) // true
Example 2: remove repeated characters from a string in javascript
const unrepeated = (str) => [...new Set(str)].join('');
unrepeated("hello"); //➞ "helo"
unrepeated("aaaaabbbbbb"); //➞ "ab"
unrepeated("11112222223333!!!??"); //➞ "123!?"