Last active
April 10, 2018 09:09
-
-
Save vishw33/51ea1fe9d82735330fe36886642804bd to your computer and use it in GitHub Desktop.
Revisions
-
vishw33 revised this gist
Apr 10, 2018 . 1 changed file with 20 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,23 @@ 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() -
vishw33 created this gist
Apr 10, 2018 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,5 @@ 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()