Skip to content

Instantly share code, notes, and snippets.

@camiloibarrayepes
Created March 3, 2022 16:58
Show Gist options
  • Select an option

  • Save camiloibarrayepes/cd88f985a0952f9130a5a0691bb04555 to your computer and use it in GitHub Desktop.

Select an option

Save camiloibarrayepes/cd88f985a0952f9130a5a0691bb04555 to your computer and use it in GitHub Desktop.
import UIKit
let ratings = [4, 8, 9.5, 2,6, 7, 3.5, 5.9, 1.5, 3.3, 9]
let results = ratings.reduce(into [:]) { (results: inout [String: Int], rating: Double) in
switch rating {
case 1..<4: results["Very bad", default: 0] += 1
case 4..<6: results["Ok", default: 0] += 1
case 6..<8: results["Good bad", default: 0] += 1
case 8..<11: results["Excellent", default: 0] += 1
default: break
}
}
print(results)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment