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
See more stuff like this over @ Snippet Zone
Oldest comments (0)