What I need is the remove both original character and its duplicates regardless if its lowercase or uppercase. also it should retain if its uppercase or lowercase
Here is my current code but it can't filter if the string is uppercase then lowercase.
const removeDuplicateChar = s => s .split('') .filter( ( cur, index, self ) => self.lastIndexOf( cur ) === self.indexOf( cur ) ) .join('')
'services' becomes 'rvic' 'stress' becomes 'tre' 'ServicEs' becomes 'ServicEs' 'streSs' becomes 'treS' 'DeadSea' becomes 'DdS'
'services' should be 'rvic' 'stress' should be 'tre' 'ServicEs' should also be 'rvic' 'streSs' should also be 'tre' 'DeadSea' becomes 'S'
You need to compare the
indexOf of the character's instance and use
s as reference so that, you won't need to use
self and join it to be a string again.
const filterDuplicateCharacters = s => s .split('') .filter((c) => s.toLowerCase().lastIndexOf(c.toLowerCase()) === s.toLowerCase().indexOf(c.toLowerCase())) .join('')