1/10: This code should add a clamped()
method to Int
that makes sure its value is between a minimum and maximum.
If you clamp the number 5 between 3 and 8, you'll get back 5.
}
if (self > max) {
} else if (self < min) {
func clamped(min: Int, max: Int) -> Int {
extension Int {
return min
}
}
return self
return max
Link copied to your pasteboard.