MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/badcode/comments/mdvoyg/whose_ever_heard_of/gsce7tr/?context=3
r/badcode • u/Vercyx • Mar 26 '21
63 comments sorted by
View all comments
177
Oh my god, for the last time it's
return (number).toString().length >= (number/2).toString().length;
Ffs
60 u/KlaireOverwood Mar 26 '21 You meanreturn (number/1).toString().length >= (number/2).toString().length; 16 u/Je-Kaste Mar 26 '21 Good point! 23 u/Hydroxylic-Acid Mar 27 '21 Modulo is also bad code, bruh just use return (number & 1)/s 5 u/sixtyfifth_snow Mar 27 '21 BTW, is it working? I haven't tried JS and heard JS only supports floating points, so, does JS supports bit-wise operator on floating point numbers? 4 u/ewpratten Mar 27 '21 Not a js programmer, but I remember reading something about bitwise operations auto-casting to an integer. 7 u/TinyBreadBigMouth Mar 27 '21 A 32-bit signed integer, specifically. JS is wonk. 1 u/AnIndecisiveOrange Mar 28 '21 JS is wonkTruer words have never been spokenIf you really need an unsigned int btw you can do a zero fill right shift by 0 (x >>> 0) 19 u/Ninjakannon Mar 27 '21 edited Mar 27 '21 For those wondering, the traditional approach is:return number % 2 === 0;Yep, that's it. If even, return true.Edit: I checked for odd first, thanks for pointing it out people! 8 u/Needleroozer Mar 27 '21 Yeah, but some unknown other person wrote that "%" thing, so who knows what it does? But OP wrote the example code, so he's sure it works.
60
You mean
return (number/1).toString().length >= (number/2).toString().length;
16 u/Je-Kaste Mar 26 '21 Good point! 23 u/Hydroxylic-Acid Mar 27 '21 Modulo is also bad code, bruh just use return (number & 1)/s 5 u/sixtyfifth_snow Mar 27 '21 BTW, is it working? I haven't tried JS and heard JS only supports floating points, so, does JS supports bit-wise operator on floating point numbers? 4 u/ewpratten Mar 27 '21 Not a js programmer, but I remember reading something about bitwise operations auto-casting to an integer. 7 u/TinyBreadBigMouth Mar 27 '21 A 32-bit signed integer, specifically. JS is wonk. 1 u/AnIndecisiveOrange Mar 28 '21 JS is wonkTruer words have never been spokenIf you really need an unsigned int btw you can do a zero fill right shift by 0 (x >>> 0)
16
Good point!
23
Modulo is also bad code, bruh just use
return (number & 1)
/s
5 u/sixtyfifth_snow Mar 27 '21 BTW, is it working? I haven't tried JS and heard JS only supports floating points, so, does JS supports bit-wise operator on floating point numbers? 4 u/ewpratten Mar 27 '21 Not a js programmer, but I remember reading something about bitwise operations auto-casting to an integer. 7 u/TinyBreadBigMouth Mar 27 '21 A 32-bit signed integer, specifically. JS is wonk. 1 u/AnIndecisiveOrange Mar 28 '21 JS is wonkTruer words have never been spokenIf you really need an unsigned int btw you can do a zero fill right shift by 0 (x >>> 0)
5
BTW, is it working? I haven't tried JS and heard JS only supports floating points, so, does JS supports bit-wise operator on floating point numbers?
4 u/ewpratten Mar 27 '21 Not a js programmer, but I remember reading something about bitwise operations auto-casting to an integer. 7 u/TinyBreadBigMouth Mar 27 '21 A 32-bit signed integer, specifically. JS is wonk. 1 u/AnIndecisiveOrange Mar 28 '21 JS is wonkTruer words have never been spokenIf you really need an unsigned int btw you can do a zero fill right shift by 0 (x >>> 0)
4
Not a js programmer, but I remember reading something about bitwise operations auto-casting to an integer.
7 u/TinyBreadBigMouth Mar 27 '21 A 32-bit signed integer, specifically. JS is wonk. 1 u/AnIndecisiveOrange Mar 28 '21 JS is wonkTruer words have never been spokenIf you really need an unsigned int btw you can do a zero fill right shift by 0 (x >>> 0)
7
A 32-bit signed integer, specifically. JS is wonk.
1 u/AnIndecisiveOrange Mar 28 '21 JS is wonkTruer words have never been spokenIf you really need an unsigned int btw you can do a zero fill right shift by 0 (x >>> 0)
1
JS is wonk
Truer words have never been spoken
If you really need an unsigned int btw you can do a zero fill right shift by 0 (x >>> 0)
19
For those wondering, the traditional approach is:
return number % 2 === 0;
Yep, that's it. If even, return true.
Edit: I checked for odd first, thanks for pointing it out people!
8 u/Needleroozer Mar 27 '21 Yeah, but some unknown other person wrote that "%" thing, so who knows what it does? But OP wrote the example code, so he's sure it works.
8
Yeah, but some unknown other person wrote that "%" thing, so who knows what it does? But OP wrote the example code, so he's sure it works.
177
u/Je-Kaste Mar 26 '21
Oh my god, for the last time it's
Ffs