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

1 Answer

0 votes
import Foundation

func removeCommonLetters(_ word1: String, _ word2: String) -> String {
    return String(word1.filter { !word2.contains($0) })
}

let word1 = "forest"
let word2 = "tor"

let result = removeCommonLetters(word1, word2)

print(result) 



/*
run:
   
fes

*/

 



answered Jul 9, 2025 by avibootz
...