Skip to content

Instantly share code, notes, and snippets.

@Li-Bot

Li-Bot/performance_chaining.swift Secret

Last active Mar 6, 2020
Embed
What would you like to do?
// Swift
let sum = fahrenheit.map({ (degreesFahrenheit) -> Double in
return (degreesFahrenheit - 32.0) / 1.8
}).filter({ (degreesCelsius) -> Bool in
return degreesCelsius <= 20.0
}).reduce(0.0) { (result, degreesCelsius) -> Double in
return result + degreesCelsius
}
// For-in loop
var sum: Double = 0.0
for degreesFahrenheit in fahrenheit {
let degreesCelsius = (degreesFahrenheit - 32.0) / 1.8
if degreesCelsius <= 20.0 {
sum += degreesCelsius
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.