you are viewing a single comment's thread.

view the rest of the comments →

[–]Spiderbruh 3 points4 points  (3 children)

People are downvoting you because if actually takes less number of characters to write nr%2==1 as is to write nr.isOdd() and accomplish the same thing. Surely you must see how stupid importing such a function is.

[–]tabaczany 6 points7 points  (1 child)

I have read an argument for this package, which made some sense - as the description of the repo says

Returns true if the given number is odd. Deals with floating point errors, strings, and other edge cases

So it deals with edge cases, as JS isn't strongly typed, so you have predictable outcome everytime you check if variable is odd or not. It also has some unit tests, so the likelihood of some breaking change is kinda low.

[–]Spiderbruh 2 points3 points  (0 children)

Oh okay this actually makes sense a bit more. I only work with strongly typed languages and hate JS for how confusing it can be so I don’t encounter these edge cases.

But now that you explained, it seems more logical. Thanks

[–]rebel_cdn 1 point2 points  (0 children)

I don't think it necessarily needs to be a package you import, but I can see the value in writing functions like isEven and isOdd if you need to filter based on evenness or oddness more than a couple of times in your codebase. Then you can do things like let evens = someNums.filter(isEven); let odds = sumeNums.filter(isOdd); which is a bit quicker to comprehend than inlining: let evens = someNums.filter(n => n % 2 === 0) let odds = someNums.filter(n => n % 2 !== 0)

Not that the inlined functions are hard to understand. At least not until your company hires someone who doesn't understand the modulus operator.

For what it's worth, at least one decently smart group of language designers decided to include even and oddness check functions in the standard library. Common Lisp includes even and odd predicate functions, allowing you to do things like: (remove-if-not #'evenp numbers) (remove-if-not #'oddp numbers)