Created
December 3, 2017 14:17
-
-
Save awedeebawe/b8b518b28199fef72555d2a37b1820ce to your computer and use it in GitHub Desktop.
"Test-Driven iOS Development with Swift 4"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func numberOfVowels(in string: String) -> Int { | |
let vowels: [Character] = ["a", "e", "i", "o", "u"] | |
/* | |
`characters` is deprecated | |
return string.characters.reduce(0) { | |
$0 + (vowels.contains($1) ? 1 : 0) | |
} | |
*/ | |
return string.lowercased().reduce(0) { // instead of adding capitalization in the `vowels` array | |
$0 + (vowels.contains($1) ? 1 : 0) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment