How to remove non-duplicate characters from string in Node.js

1 Answer

0 votes
const removeNonDuplicate = str => {
   const arr = str.split("");
    
   const duplicateArray = arr.filter(ch => {
        return arr.indexOf(ch) !== arr.lastIndexOf(ch);
   });
    
   return duplicateArray.join("");
}
 
const str = "Bubble Occurrence Mammal node";
 
console.log(removeNonDuplicate(str));
 
 
 
 
/*
run:
 
ubble ccurrence ammal ne
 
*/

 



answered Mar 20, 2024 by avibootz
...