4 ms·
typeof x !== “number” ? false : x % 2 === 0
by leodriesch 4y ago
typeof x !== “number” ? false : x % 2 === 0
- UncleMeat 4y agoSomebody in your codebase is going to use !isEven(x) to test for isOdd and introduce a bug. IMO, it should crash if passed a non-number.
- lmkg 4y agoActually it's the other way around. The isEven package has one dependency, which is the isOdd package. I am literally not joking. https://www.npmjs.com/package/is-even https://www.npmjs.com/package/is-even
- johnchristopher 4y agohttps://www.npmjs.com/package/is-odd-and-even https://www.npmjs.com/package/is-odd-and-even I don't know what to say. /** * is-odd-and-even * Github: https://github.com/fabrisdev/is-odd-and-even */ import isOdd from 'is-odd' import isEven from 'is-even' /** * @param {number | string} i The number to check if it's odd and even * @returns {boolean} True if the number is odd and even, false otherwise */ export default function isOddAndEven(i){ return isOdd(i) && isEven(i) }
- UncleMeat 4y agoIsOdd and IsEven are so famous that it would not surprise me at all if there a bunch of joke modules using them.
- UncleMeat 4y agoIndependent of the insanity that is the npm ecosystem, the API design skill of handling invalid input in a bug-resistant way is important. If somebody sent me a code review with isEven implemented as "typeof x !== “number” ? false : x % 2 === 0" I'd tell them to fix it.