Created
March 31, 2018 08:47
-
-
Save iamcrypticcoder/ddf5eb1941e9dc52ba22391f7f81edd0 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
import Foundation | |
protocol PostAnalyzeStrategy { | |
func analyze(_ posts: [Post]) -> Void | |
} | |
class SadnessAnalysisStrategy : PostAnalyzeStrategy { | |
func analyze(_ posts: [Post]) -> Void { | |
let postCount: Int = posts.count | |
var totalSadCount: Int = 0 | |
for post in posts { | |
totalSadCount += post.sadCount | |
} | |
let val: Double = Double(totalSadCount / postCount) | |
print("Laugh Value: \(val)") | |
} | |
} | |
class LaughAnalyzeStrategy : PostAnalyzeStrategy { | |
func analyze(_ posts: [Post]) -> Void { | |
let postCount: Int = posts.count | |
var totalLaughCount: Int = 0 | |
for post in posts { | |
totalLaughCount += post.laughCount | |
} | |
let val: Double = Double(totalLaughCount / postCount) | |
print("Laugh Value: \(val)") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment