Skip to content

Instantly share code, notes, and snippets.

@iamcrypticcoder
Created March 31, 2018 08:47
Show Gist options
  • Save iamcrypticcoder/ddf5eb1941e9dc52ba22391f7f81edd0 to your computer and use it in GitHub Desktop.
Save iamcrypticcoder/ddf5eb1941e9dc52ba22391f7f81edd0 to your computer and use it in GitHub Desktop.
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