orhtej2@eviltoast.org to Programmer Humor@programming.devEnglish · 2 days agoPeak code reuseeviltoast.orgimagemessage-square41linkfedilinkarrow-up1456arrow-down15
arrow-up1451arrow-down1imagePeak code reuseeviltoast.orgorhtej2@eviltoast.org to Programmer Humor@programming.devEnglish · 2 days agomessage-square41linkfedilink
minus-squareDecq@lemmy.worldlinkfedilinkarrow-up2arrow-down1·edit-21 day ago If string return nan, else % 2 So now you return a number type if it’s a string and a boolean if it’s an integer. How does that make sense? The is-even lib exists to sanitize input by throwing an exception which imho is better. Edit: having looked at the code better. Apparently it still allows string coercion (boo). It only checks for non integer numbers.
minus-squarebobo@lemmy.mllinkfedilinkarrow-up1·1 day agoGood point, but you can do if === true… and else if === false… But definitely better to throw an error instead of nan.
So now you return a number type if it’s a string and a boolean if it’s an integer. How does that make sense?
The is-even lib exists to sanitize input by throwing an exception which imho is better.
Edit: having looked at the code better. Apparently it still allows string coercion (boo). It only checks for non integer numbers.
Good point, but you can do if === true… and else if === false…
But definitely better to throw an error instead of nan.
deleted by creator