How to remove the letters from word1 if they exist in word2 with Node.js

1 Answer

0 votes
function removeCommonLetters(word1, word2) {
  let result = '';
  
  for (const char of word1) {
    if (!word2.includes(char)) {
      result += char;
    }
  }
  
  return result;
}

// You can export the function if you want to use it as a module
module.exports = removeCommonLetters;

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

const result = removeCommonLetters(word1, word2);

console.log(result);




/*
run:

fes

*/

 



answered Jul 9, 2025 by avibootz
...