How to remove the letters from word1 if they exist in word2 with TypeScript

1 Answer

0 votes
function removeCommonLetters(word1: string, word2: string): string {
  let result: string = '';

  for (const char of word1) {
    if (!word2.includes(char)) {
      result += char;
    }
  }

  return result;
}

const word1: string = "forest";
const word2: string = "tor";

const result: string = removeCommonLetters(word1, word2);

console.log(result);




/*
run:

"fes" 

*/

 



answered Jul 9, 2025 by avibootz
...