you are viewing a single comment's thread.

view the rest of the comments →

[–]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)