Skip to main content

app-ads.txt

 google.com, pub-2203413632152319, DIRECT, f08c47fec0942fa0

Find Out How Many Number of Vowels & Vowels in a Sentence & Remove duplicate elements

 

Find Out How Many Number of Vowels & Vowels in a Sentence & Remove duplicate elements

func findVowelAndCount(str: String) -> (vowelCount: Int, vowelStr: String) {

        let vowels = "aeious"

        var vowelsCounts = 0

        var vowelsArray: [String] = []

        var volsStr = ""

        

        for i in str.lowercased(){

            if vowels.contains(i){

                vowelsCounts += 1

                if !vowelsArray.contains("\(i)"){

                    vowelsArray.append("\(i)")

                }

            }

            volsStr = vowelsArray.joined()

        }

        return (vowelsCounts, volsStr)

    }


  //MARK: - Output

    

 let vowelsOutput = findVowelAndCount(str: "How to convert character array into string in Swift?")

 print(vowelsOutput) //(vowelCount: 16, vowelStr: "oeais")

Comments