Given:
let a = 4.2 let b = -1.3 let c = 6.4
I want to know the simplest, Swiftiest way to clamp these values to a given range, say 0...
0...
The shortest (but maybe not most efficient) way to clamp, is:
let clamped = [0, a, 5].sorted()[1]
Source: user tobr in a discussion on Hacker News