That one is bad, I use this one www.npmjs.com/package/is-is-is-even
Comment on I wish
levi@aussie.zone 11 months ago
Oh man, in js we have a package for this magic.
Dewded@lemmy.world 11 months ago
Nobsi@feddit.de 11 months ago
Why even do that, just check for the opposite of www.npmjs.com/package/is-is-is-is-is-is-odd
Dewded@lemmy.world 11 months ago
Oh fuck, gonna refactor asap!
unreachable@lemmy.world 11 months ago
left-pad PTSD intensifies
Floey@lemm.ee 11 months ago
I always forget if is even requires is odd or the other way around.
gandalf_der_12te@feddit.de 11 months ago
Weekly Downloads: 293.319
Sunrosa@lemmy.world 11 months ago
I would never touch js, so idk convention, but this has to be a joke right?
KoboldCoterie@pawb.social 11 months ago
Looking at their code, it’s really just a bunch of checks to make sure the variable passed is actually an integer that it can work with, followed by the solution:
return (n % 2) === 1;
I can’t think of a more efficient way to get the answer. It does seem like it’d take more time to download the package than to just write the function yourself, though.
Sunrosa@lemmy.world 11 months ago
Ohh. JS needs you to check the variable during runtime??? That’s… something. I guess that’s what you get for using dynamic typing everywhere. I still bet it’d be faster to do the function by hand though.
levi@aussie.zone 11 months ago
It looks like this is a handlebars helper.
Handlebars is a temptating language.
I’ve never used handlebars but I’m guessing this is syntactic sugar for non-programmers. Like:
<div>{{if is-even myVariable}} it's even {{else}} it's odd {{endif}}</div>
takeda@lemmy.world 11 months ago
And it is so light, it only requires is-odd package!