How to remove element from a String with Int index

Solution 1:

I have this code but I'm not using the k, I'm counting the repetitions and remove the repetitions that I already count.

func getRepetitions(firstString: String, comparativeString: String) -> Int {
    var repetitions = 0
    var comparativeStringName = Array(comparativeString)
    for character in firstString {
        if comparativeStringName.contains(character),
           let index = comparativeStringName.firstIndex(of: character){
            comparativeStringName.remove(at: index)
            repetitions += 1
        }
    }
    return repetitions
}