Re:Math.min(Math.max(num, min), max)
by tobr on Thursday August 20, 2020 @03:31PM
(#24227667)
This should be completely obvious, but largely irrelevant to the topic at hand. The linked tweet talks about how difficult it is to remember the order of the terms when you implement clamp a certain way; I just wanted to point out that with a different solution, the order surprisingly doesn’t matter at all.
[ Parent
| on HN ]
Re:Math.min(Math.max(num, min), max)
by seanwilson on Thursday August 20, 2020 @03:42PM
(#24227842)
I don't think it's obvious though - many people have never optimised for garbage collection so I thought it was worth pointing out.
I still found your approach interesting and it's rare there's a perfect approach so don't take it to heart.