• Decq@lemmy.world
    link
    fedilink
    arrow-up
    2
    arrow-down
    1
    ·
    edit-2
    18 hours 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.

    • bobo@lemmy.ml
      link
      fedilink
      arrow-up
      1
      ·
      17 hours ago

      Good point, but you can do if === true… and else if === false…

      But definitely better to throw an error instead of nan.