1function removeDuplicateCharacters(string) {
2 return string
3 .split('')
4 .filter(function(item, pos, self) {
5 return self.indexOf(item) == pos;
6 })
7 .join('');
8}
9console.log(removeDuplicateCharacters('baraban'));
1const unrepeated = (str) => [...new Set(str)].join('');
2
3unrepeated("hello"); //➞ "helo"
4unrepeated("aaaaabbbbbb"); //➞ "ab"
5unrepeated("11112222223333!!!??"); //➞ "123!?"
1const arr = [1, 2, [3, 4]];
2
3// To flat single level array
4arr.flat();
5// is equivalent to
6arr.reduce((acc, val) => acc.concat(val), []);
7// [1, 2, 3, 4]
8
9// or with decomposition syntax
10const flattened = arr => [].concat(...arr);
11