That way you force true or false instead of returning the result of num % 2.
Nothing is wrong with that
Except why does it have two exclamation points?
this would not pass code review since !! is overly clever
should probably be something like Boolean(num%2) for the sake of readability/clarity
2 years ago
Anonymous
It should be `n mod 2 == 1` to clearly show how this works, rather than relying on the reader knowing some quirk of the language on truthy / falsy non Boolean type values
Alternatively stop being moronic and learn how to read """smart""" code
2 years ago
Anonymous
Should developers dumb down their work to the lowest possible level so even the very stupid or mentally damaged can read it?
2 years ago
Anonymous
No. If it works and it's not in some obscure duct taped method put together then it's good.
>JS babbies are something else
if that something else is lazy, poorly educated and dangerously incompetent.. then yes, they sure are. there's a lot of fricking morons out there that are so lazy that they'd rather import a dependency than code it themselves, no matter how small the routine is.
You know that screenshot of interview questions where the guy asked people to write a program that finds odd numbers and most didn't know how to do it?
> node.js inherits from web not having a functional standard library, making supply chain attacks feasible
except in node, people don't even need to make it a "framework". The whole npm is a framework
shut the frick up phone poster
looks like a tablet to me
what's wrong with const isOdd = num => !!(num%2)?
Nothing is wrong with that
Except why does it have two exclamation points?
That way you force true or false instead of returning the result of num % 2.
To turn 1 to true, moron
this would not pass code review since !! is overly clever
should probably be something like Boolean(num%2) for the sake of readability/clarity
It should be `n mod 2 == 1` to clearly show how this works, rather than relying on the reader knowing some quirk of the language on truthy / falsy non Boolean type values
Alternatively stop being moronic and learn how to read """smart""" code
Should developers dumb down their work to the lowest possible level so even the very stupid or mentally damaged can read it?
No. If it works and it's not in some obscure duct taped method put together then it's good.
0.5 is now odd?
Here's v1.1: const isOdd = n => !!(n%2&&!(n%1))
comparing with is-odd module
doesn't throw an error if num isn't a number
>> isOdd("3")
<- true
doesn't throw an error if num is float
>> isOdd(3.1)
<- true
>> isOdd(4)
<- false
>> isOdd(4.1)
<- true
doesn't throw an error if num excess max safe integer
welcome to the zoo that JS is
Either use
or move on to TypeScript because you're too shit at writing code.
though not sure that just returning a float isn't odd is correct
still following happens
>> isOdd("3")
<- true
come on anon you can do it
3 is odd, moron.
"3" is a string
"3" can be compared to a number in JS. It's part of the spec. If you want strict typecasting, again use TypeScript. Jesus fricking Christ.
Numbers > max safe integer are all even integers, so it should clearly return false for those.
Bros i bet like 99% no 100% thats right. 100% of these webshitters are not dealing with inputs.
reinventing the wheel is moronic, use the library
I don't want to bloat up my codebase with 120KB of shit.
extremely moronic and slow
use bitwise operations
>400k weekly downloads
JS babbies are something else
>JS babbies are something else
if that something else is lazy, poorly educated and dangerously incompetent.. then yes, they sure are. there's a lot of fricking morons out there that are so lazy that they'd rather import a dependency than code it themselves, no matter how small the routine is.
>dangerously incompetent
there is nothing dangerous about web dev
>bro just import modules for every mundane task nothing can go wrong you can trust JS soidevs
You know that screenshot of interview questions where the guy asked people to write a program that finds odd numbers and most didn't know how to do it?
I don’t give a shit you stupid piece of shit enjoy the ride YOU are on THE HIGHWAY now
#define isOdd(n) (1 == (n) % 2)
Uhm, sorry sweatie, that is not valid JS.
>doesn't work for negatives
Resume:
Author of code repository on <site> with over 368,000 downloads per week.
>meanwhile all the code they wrote is
and an export function for it
What if I'm not rich?
Every single time this comes up all the donner kruger morons give an implementation that doesn't work on negative numbers. Always makes me laugh.
In this thread I learned that 1.5 is odd and -1 is even.
> node.js inherits from web not having a functional standard library, making supply chain attacks feasible
except in node, people don't even need to make it a "framework". The whole npm is a framework
Introduce a massive security vulnerability to save under 10 characters of code. Very JS pilled.
Do Java tards really not know how to check if an int is odd?
>Java
You're moronic yourself, sub 70 IQ fellow.
#define IS_ODD(N) (N & 1)
Not JS.
I think i found the culprit
https://www.spreadsheetweb.com/isodd-excel-function/
Maybe its just accountants using googlesheets or something
Just fricking
Math.floor(Math.abs(num))%2==0
Jesus christ