3 ms·
JavaScript's weak typing and implicit type conversions get in the way of reasonability though: >>> '13' % 2 0 >>> 'nan' % 2 NaN >>> NaN % 2 NaN >
by Phemist 1y ago
JavaScript's weak typing and implicit type conversions get in the way of reasonability though:
>>> '13' % 2
0
>>> 'nan' % 2
NaN
>>> NaN % 2
NaN
>>> null % 2
0
this package ensures that you have a sane complement to is-odd, e.g. `!isOdd(someVar)` is always even (in the domain of natural numbers). A naive implementation of is-odd: `(some_var % 2 === 1)`, does not have a sane complement.
Anyway, to include this package as a dependency is indeed overkill. I would most likely opt for vendoring this package into the project (including licenses and acknowledgement), as the code is unlikely to change and is MIT licensed.
- johannes1234321 1y agoThe question is: how likely is it that I get the trash input in and do I care about the result if the input is trash? Modulo two works well for a lot of cases where this is needed. (Which probably is size of a container (array) or alternating something in a loop.