Re:I'm a fucking webmaster (2016)
by dncornholio on Monday May 09, 2022 @01:16PM
(#31316864)
> if you encounter it frequently enough
That's a huge if!
So abstracting a one line in a function is actually good. Putting it up on npm is debatable.
n % 2 or n & 1 is something you likely get used to if you encounter it frequently enough, and at least something you should recognize after the first time you encounter it. And most people should have encountered it at least once because that's one of the things we learn to do when learning programming (but I guess Ten Thousand [1] can apply). If you don't encounter it enough to be used to it, then the rare gymnastic should not be a big issue neither. You need to be able to recognize it because it's in the wild.
If having an isOdd or isEven function around makes the code more readable for you anyway it's fine, especially if the function can be inlined, but pulling an external dependency for this is overkill.
[1] https://xkcd.com/1053/