Skip to content

Instantly share code, notes, and snippets.

@vishw33
Last active April 10, 2018 09:09
Show Gist options
  • Select an option

  • Save vishw33/51ea1fe9d82735330fe36886642804bd to your computer and use it in GitHub Desktop.

Select an option

Save vishw33/51ea1fe9d82735330fe36886642804bd to your computer and use it in GitHub Desktop.
extension Array where Element == String
{
func totalCharacterCount() -> Int
{
return reduce(0, { $0 + $1.count})
}
func wordCount() -> Int
{
return reduce(0, {$0 + $1.components(separatedBy: " ").count})
}
func elementCharacterCount() -> [Int]
{
var countArray:[Int] = [Int]()
countArray = map{$0.count}
return countArray
}
}
let arrayString:[String] = ["The Godfather" , "The Shawshank Redemption" , "Schindler's List" , "Raging Bull" , "Gone with the Wind" , "The Wizard of Oz" , "Lawrence of Arabia" , " Forrest Gump"]
let characterCount = arrayString.totalCharacterCount()
let wordCount = arrayString.wordCount()
let eachCharacterCount = arrayString.elementCharacterCount()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment