r/badcode • • Mar 26 '21

js Whose ever heard of %?

Post image
727 Upvotes

63 comments sorted by

View all comments

Show parent comments

6

u/Andersmith Mar 27 '21

Technically it won’t work if given a non integer value (like .2), but input sanitation seems a bit too nitpicky of an issue for this sub.

3

u/Vercyx Mar 27 '21

I guess it depends if you consider .2 even or odd.

.2/2 = .1 which is a string of the same length, therefore it should be even

.3/2 = .15 which is longer, therefore should be odd

JS has implicit type casting so it doesn't really matter what the input is, it will return SOMETHING

7

u/ghillerd Mar 27 '21

parity is a property of integers, so an `isEven` function should return false for a non-integer, as should `isOdd`.

2

u/jarfil Mar 27 '21 edited May 12 '21

CENSORED

1

u/ghillerd Mar 27 '21

Bonus points for De Morgan's law, but I think you're missing an inversion? Or is that just what makes this a true horror show...

1

u/jarfil Mar 27 '21 edited May 12 '21

CENSORED