Last active
April 10, 2018 09:09
-
-
Save vishw33/51ea1fe9d82735330fe36886642804bd to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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