News for hackers. Stuff that matters.
Re:Math.min(Math.max(num, min), max) by mabbo on Thursday August 20, 2020 @02:21PM (#24226577)
You know what's great about that? The order of the arguments doesn't matter. So all the debate about "should it be num, min, max or min, num, max"- your solution does not care. Put them in any order you like!

You've redefined the problem from clamping a given value into picking the middle value from 3. This is a lovely way to re-interpret it.

Re:Math.min(Math.max(num, min), max) by thaumasiotes on Thursday August 20, 2020 @02:44PM (#24226960)
Well, the order of the arguments does matter. Sorting three values requires 2.67 comparisons where clamping a value between two other values requires exactly 2. There are plenty of contexts where cleverly avoiding a problem by doing 33% more work isn't viewed as desirable.
Re:Math.min(Math.max(num, min), max) by jonahx on Thursday August 20, 2020 @11:13PM (#24231591)
True, but I think there are more situations where minimizing the chance of programmer error, now or in the future, is more important than a micro-optimization that will never matter. All depends on context.