How to find missing alphabet characters from a string in Swift

1 Answer

0 votes
import Foundation

func getMissingAlphabetChars(_ input: String) -> [Character] {
    // Full alphabet as a Set
    let alphabet = Set("abcdefghijklmnopqrstuvwxyz")

    // Normalize input: lowercase + keep only letters a–z
    let present = Set(
        input.lowercased().filter { $0.isLetter && $0.isASCII && $0.isLowercase }
    )

    // Difference: alphabet minus present letters
    return Array(alphabet.subtracting(present)).sorted()
}

let missing = getMissingAlphabetChars("Swift Programming")

print(missing)



/*
run:

["b", "c", "d", "e", "h", "j", "k", "l", "q", "u", "v", "x", "y", "z"]

*/

 



answered Mar 8 by avibootz
...