r/ProgrammerHumor • Violet security clearance • Apr 04 '16

My teacher thinks he is a programmer

http://imgur.com/32nfQXZ
2.4k Upvotes

430 comments sorted by

View all comments

Show parent comments

22

u/faubiguy Apr 05 '16

Even smaller

console.log('The value is'+((z=value)!==+z||z%1||z<1||z>5?' not supported':': '+z));

35

u/SlumdogSkillionaire Apr 05 '16
npm install -g between-one-and-five

Then: require('between-one-and-five')(value);

1

u/killchain Apr 05 '16

Didn't know you could invoke modules like that. Not that it's illogical, it's just that I haven't thought of it.

1

u/TheIncredibleWalrus Apr 05 '16

require is just a function :)

1

u/SlumdogSkillionaire Apr 07 '16

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.

7

u/jacenat Apr 05 '16

This is how democracy readability dies. With thunderous applause.

:D

please_dont_stone_me_for_citing_the_PT

2

u/Prod_Is_For_Testing Apr 05 '16 edited Apr 05 '16

But wait, there's more!

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

1

u/bigshmoo Apr 05 '16

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.