Skip to content

Instantly share code, notes, and snippets.

@awedeebawe
Created December 3, 2017 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save awedeebawe/b8b518b28199fef72555d2a37b1820ce to your computer and use it in GitHub Desktop.
Save awedeebawe/b8b518b28199fef72555d2a37b1820ce to your computer and use it in GitHub Desktop.
"Test-Driven iOS Development with Swift 4"
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