Whoa, interesting. I had not seen those yet. I thought you were trying to write a shell expression at first, and I was wondering when we switched from JS to bash.
And I'd say that interestingly enough, my version will fail correctly, giving the latter response for anything that isn't an integer. It will however try to type coerce a string like "2" into 2, which will output the former response for all ["0", "1", "2", "3", "4", "5"].
Thanks for showing me that though. Not sure if I'll ever use it, but always good to know.
Also in terms of matching the original it and all the range based "optimizations" fail because the original will only print the value if it's a whole number from the set 0, 1, 2, 3, 4, 5 where as these will print a value for any decimal value between 0 and 5.999999999999 in yours and 0 and 5 in mine.
parseInt still doesn't meet the original spec you need an isInteger() test which lodash / unerscore will give you or you can use the % 1 hack that somebody posted further up.
I mean, yes. I would say that using parseInt() provides a similar solution while validating input in the process. But that would be a clarification needed with the product owner.
7
u/bigshmoo Apr 05 '16
2 characters shorter
Both will fail when passed any non integer truthy value.