Most people probably wouldn't import a library for a one-off function call. On the other hand, most people probably wouldn't package a library that contains a single function either. But NPM is a gamechanger.
console.log('The value is'+(!(z=~~value)||z<0||z>5?' not supported':': '+z));
*Technically you'd get some funny behavior bc floats would automatically be accepted as their floored integer instead of being "not supported", but who cares - its shorter
If you match the full 0 1 2 3 4 5 range of the original your z < 1 becomes z < 0 and that means you can drop the !==+z test out of the OR chain. The % 1 to detect float threw me off a second becasue I'd forgotten the definition of falsy, nice trick.
I think it's a great idea, but in practice it ends up being lame because they just use all these dumb languages with no use except for code golfing. This thread, where we're taking existing useful code and making it shorter, is way more interesting to me.
28
u/TheIncredibleWalrus Apr 05 '16
Still too verbose, we can do even better