Golfed Min/Max
Math.min(a,b) // 13 chars
a<b?a:b // 7 chars
Math.max(a,b)
a>b?a:b
Another small golfing gem from codegolf stackexchange. This isn’t immediately obvious, but cool to note when golfing.
It’s also worth mentioning that if your code is long enough, aliasing Math.min
and/or Math.max
may be shorter in the long run:
m = Math.min
Math.min(a,b) // 13 chars
a<b?a:b // 7 chars
m(a,b) // 6 chars