r/shittyprogramming • u/Noahcoolbot • Mar 03 '22
Optimized Math.floor in JavaScript
// Stolen from stackoverflow
function howManyDecimalsDoesThisHave(thisthing) {
let 数字 = 0;
while(Math.floor(thisthing) != thisthing) {
thisthing = thisthing * 10;
数字 = 数字 + !(NaN == NaN)
}
return 数字;
}
function MoDuLo(a,k, smart = 0) {
global.returnvalue = "nyoom"
if(Math.random() > 0.5) {
var MAINFRAME = a / k
if(smart < 3)
MoDuLo(MAINFRAME, 1, smart + (![] == []))
let _ = smart >= 3 ? Math.floor(MAINFRAME) : (MAINFRAME - global.returnvalue)
global.returnvalue = a - _ * k
}
if(Math.random() > 0.5) {
// It's been 2 weeks since I wrote this, and I don't understand how this works anymore
const IllIllIIIIlIlI = a
const IllIllIIlIlIlI = k
let IlIIllIIlIlIlI = IllIllIIIIlIlI
while(true) {
if(IlIIllIIlIlIlI < IllIllIIlIlIlI) {
break
}
IlIIllIIlIlIlI = IlIIllIIlIlIlI - IllIllIIlIlIlI
}
global.returnvalue = IlIIllIIlIlIlI
}
if(Math.random() > 0.9 || global.returnvalue == "nyoom") {
throw new Error("Error")
}
}
// Optimized using quantum computing and
function round_down(nmuber, coolargument) {
while(true) {
try {
// I was eating peanut M&Ms while writing this, and I don't have any more :(
MoDuLo(nmuber, 1)
if(global.returnvalue == 0) {
return nmuber;
}
let crèpes = nmuber
let javasiptdownloadfree2022novirus = Math.random() * 10 ** howManyDecimalsDoesThisHave(crèpes)
MoDuLo(javasiptdownloadfree2022novirus, 1)
javasiptdownloadfree2022novirus = javasiptdownloadfree2022novirus - global.returnvalue
// hey cortana how to deactivate speech to text
MoDuLo((crèpes * 10 ** howManyDecimalsDoesThisHave(crèpes) - javasiptdownloadfree2022novirus) / 10 ** howManyDecimalsDoesThisHave(crèpes), 1)
if(global.returnvalue == 0) {
return nmuber - javasiptdownloadfree2022novirus / 10 ** howManyDecimalsDoesThisHave(crèpes)
}
} catch(e) {
// TODO: Handle errors properly
}
}
}
console.log(round_down(6.125))
Without having to use any npm modules like a big boy 😁
It becomes exponentially slower the more decimals you add, but I'm sure someone will fix it for me!
120
Upvotes
66
u/timawesomeness Mar 03 '22
This is actually a feature, it encourages shorter numbers which forces the user to optimize their code :)
20
u/KSAM-The-Randomizer Mar 03 '22
what in the fuck did I witness
18
u/battlekip Mar 03 '22
Thanks, I hate it
16
u/Spritetm Mar 04 '22
Bonus points for using Math.floor in your function that is supposed to replace Math.floor.
14
u/metakirby5 Mar 04 '22
I like how you use
Math.floorin your optimizedMath.floor. It's like recursion, except you don't have to worry about infinite loops!11
u/Shortl4ndo Mar 04 '22
TIL you can use non-ascii characters as variable names
2
u/[deleted] Mar 03 '22
I love this omg
2
u/KingOfKingOfKings Mar 04 '22
coolargumentmade me lose it2
u/zarmin Mar 04 '22
it's very subtle
1
u/encrypter8 Mar 04 '22
gtfo.gif
1
u/[deleted] Mar 04 '22
What the hell did I just read?
1
u/Aphix Mar 18 '22
Actually optimized:
~~(number)Note: Does not work for negative values.
0
u/[deleted] Mar 04 '22
[deleted] — view deleted comment