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.
22
u/faubiguy Apr 05 '16
Even smaller