• NotAViciousCyborg@lemmy.world
    link
    fedilink
    arrow-up
    27
    ·
    6 months ago

    I thought I was missing something. JS is one of my main languages and I always just write the is-odd function myself since it’s like 10 characters. It boggles the mind that is-even has 176k weekly downloads

    • kevincox@lemmy.ml
      link
      fedilink
      arrow-up
      19
      ·
      6 months ago

      To be fair having a name can make things easier to read. I get that i % 2 == 0 is a common pattern and most programmers will quickly recognize what is happening. But isEven(i) is just that much easier to grok and leaves that brainpower to work on something else.

      But I would never import a package for it. I would just create a local helper for something this trivial.

      • NotAViciousCyborg@lemmy.world
        link
        fedilink
        arrow-up
        10
        ·
        6 months ago

        Exactly what I would do if I had to reuse it, especially now since I know that adding a package would actually add 2. It all just seems so…inefficient

        • kevincox@lemmy.ml
          link
          fedilink
          arrow-up
          11
          ·
          6 months ago

          Even if the code isn’t reused adding names to sub-expressions can be very valuable. Often times I introduce new functions or variables even if they are only used once so that I can give them a descriptive name which helps the reader more quickly understand what is happening.

          • NotAViciousCyborg@lemmy.world
            link
            fedilink
            arrow-up
            3
            ·
            6 months ago

            Yeah, I do that with pretty much every separate operation in c# since our solutions are pretty big. Most of my JS scripts are just done in ServiceNow which are separated and named appropriately.

    • gaael@lemmy.world
      link
      fedilink
      arrow-up
      7
      ·
      6 months ago

      Also there are 40-something packages depending on it, so I guess it gets pulled automatically when they are used.

    • Aqarius@lemmy.world
      link
      fedilink
      arrow-up
      2
      ·
      6 months ago

      If youre lazy/busy enough, doing basic checks on the input is enough boilerplate to package out.