▲ | 0x20cowboy 16 hours ago | |||||||||||||||||||||||||||||||||||||||||||||||||
I agree with the spirit of this, but I’d go one more step with the example: export function clamp(value: number, min: number, max: number): number { return } That is just adding an extra jump and entry on the callstack where you could just have done: Math.min(Math.max(value, min), max); Where you need it. (The example used was probably just for illustration though) | ||||||||||||||||||||||||||||||||||||||||||||||||||
▲ | pigbearpig 15 hours ago | parent | next [-] | |||||||||||||||||||||||||||||||||||||||||||||||||
The author does acknowledge that in the "How it Should Be" section. | ||||||||||||||||||||||||||||||||||||||||||||||||||
▲ | chii 15 hours ago | parent | prev [-] | |||||||||||||||||||||||||||||||||||||||||||||||||
> you could just have done ... i disagree with this particular example - it's actually a good use case for being a utility maths function in a library. I mean, the very `min()` and `max()` function you used in the illustration could also have been used as an example, if you use the same logic! | ||||||||||||||||||||||||||||||||||||||||||||||||||
|