People using this deserve that their code breaks. Absolutely ridiculous.
Neither this, nor the leftpad thing, nor this is-even “package” are things I would even think about for a second before just writing it on my own. I wouldn’t even consider those features (let alone packages to depend my code on!) but basic programming.
I mean, does any language implement is_odd() natively? Doesn’t everyone implement modulus and pretty much assumes that you remember modulus from elementary and can infer that even numbers are those where x % 2 == 0.
Let’s call the number variable just x, you then have literal math (Euclidean division) if you ignore === instead of = for equals.
x % 2 === 0
This can’t get better or more native than “just math”. This is the whole code you need to detect if a number is even. I wouldn’t even call it “code”.
If you remove whitespaces and ignore the type you end up with x%2==0 which is 6 characters long and a fully valid if clause. No magic involved, no abstraction, no weird function calls on integers …
I see that in modern JS this type of coding is a trend, but you can’t tell me you want to replace 6 characters with an own module or a package. :)
No, I want that in the std lib. Yes, it would just call x % 2 == 0 underneath. But the advantage is readability. I’m in principle aware that x % 2 == 0 is true when the number is even, but I need it seldomly enough that I do still need to think about it for a second before I know for sure. I don’t need to think about x.is_even(). And the readability is what I want natively, i.e. in the std lib.
It being in the std lib would also sidestep your concerns about security or the function call having unknown side effects.
11 lines of code shouldn’t be a package.
you should see the “is_odd” package…
it’s like, return (num%2)? true:false
People using this deserve that their code breaks. Absolutely ridiculous.
Neither this, nor the leftpad thing, nor this is-even “package” are things I would even think about for a second before just writing it on my own. I wouldn’t even consider those features (let alone packages to depend my code on!) but basic programming.
Problem is when you accidentally pull it in as a transitive dependency…
Yeah :( This also is why such nonsense “breaks the Internet” …
i just don’t see how npm is letting this happen…
im going to write an npm module called “true” that just returns true…
… and that has 4 dependencies on it’s own!
deleted by creator
well although 1 evaluates as true and zero as false, it’s not the same thing…
so yes, i did…
and that’s still too verbose. it should be (num % 2) != 0
return ?(num & 1)
Name checks out
at which point do you blame the language for not implementing it natively?
I mean, does any language implement
is_odd()
natively? Doesn’t everyone implement modulus and pretty much assumes that you remember modulus from elementary and can infer that even numbers are those wherex % 2 == 0
.Erm … What more native than
number % 2
do you want to have it?2.is_even()
(I don’t know, if this is possible in JS.)
Let’s call the number variable just
x
, you then have literal math (Euclidean division) if you ignore===
instead of=
for equals.x % 2 === 0
This can’t get better or more native than “just math”. This is the whole code you need to detect if a number is even. I wouldn’t even call it “code”.
If you remove whitespaces and ignore the type you end up with x%2==0 which is 6 characters long and a fully valid
if
clause. No magic involved, no abstraction, no weird function calls on integers …I see that in modern JS this type of coding is a trend, but you can’t tell me you want to replace 6 characters with an own module or a package. :)
No, I want that in the std lib. Yes, it would just call
x % 2 == 0
underneath. But the advantage is readability. I’m in principle aware thatx % 2 == 0
is true when the number is even, but I need it seldomly enough that I do still need to think about it for a second before I know for sure. I don’t need to think aboutx.is_even()
. And the readability is what I want natively, i.e. in the std lib.It being in the std lib would also sidestep your concerns about security or the function call having unknown side effects.
Isn’t %2 already native?
(BTW this thing failed JavaScript so hard ECMA immediately included it in that year’s standard)
at 200k weekly downloads, i blame npm for allowing it…
https://www.npmjs.com/package/is-even
https://www.npmjs.com/package/undefined
What do you think about this package? 14,000 weekly downloads…
now i understand why people would call code “beautiful” and “elegant”
…
this here is a true work of art