r/badcode • u/Notimecelduv • Jul 16 '21
js f-fa-fac-fact-facto-factor-factori-factoria-factorial
57
u/deftware Jul 16 '21
Looks like another case of overengineering where someone gets paid per line of code.
12
u/grampipon Jul 16 '21
Is that really a thing? Do companies sometimes pay per line?
35
u/Lost4468 Jul 16 '21
A few megashit companies do, yes. Leave asap if you're at one. You should check out /r/cscareerquestions, the Software Engineering StackExchange, and the Workplace StackExchange for all sorts of ridiculous shit.
Another one I have seen a few times is banning employees from using places like StackOverflow, either because "it's cheating" (wtf) or "it's a social network".
17
u/AlFasGD Jul 16 '21
Damn, as if I want to know how to solve a problem which is my fucking job. I guess I won't be using SO anymore because learning is cheating.
15
u/cryptOwOcurrency Jul 16 '21
places like StackOverflow
"it's cheating"
This has to be an urban legend.
4
Jul 16 '21
Taught in every school so fraid not.
3
u/DetectivePokeyboi Jul 18 '21
It makes sense in school. They want to see if you can use your own knowledge and skill to write the code. The programs you create in class aren’t actually going to be used for anything and the grade in class and the degree you get is supposed to be representative of personal knowledge and skill.
This is not the case in jobs where all that matters is the product.
2
u/sneakpeekbot Jul 16 '21
Here's a sneak peek of /r/cscareerquestions using the top posts of the year!
#1: Why did I spend 4 year getting a CS degree for Web Development when people doing coding bootcamp for a few weeks and are able to get same jobs?
#2: My Reddit account cost me my next SDE job(95% sure)
#3: I've walked away from software development.I'm a bot, beep boop | Downvote to remove | Contact ^^me | ^^Info | ^^Opt-out
1
1
u/ExistedDim4 Jul 17 '21
Last paragraph is pure schizophrenia(and as such an object with a pure schizophrenia function cannot be constructed)
1
u/deftware Jul 16 '21
Dumb ones mostly, where there's a handful of coders and a lot more managerial types.
1
Jul 16 '21
Or worse, your CFO is your manager.
1
u/deftware Jul 16 '21
Then you can get away with fluffing code up as much as possible! During code reviews you just vaguely point at stuff "oh yeah so this part calculates the factorial, I had a great idea to store a seed value in an object ... " blah blah blah just placating the n00b making him think he's hot shit for hiring you - the code rockstar.
35
47
16
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Jul 16 '21
Image Transcription: Code
let factorial = {
seed : 1,
next : function() {
return {
value : this.seed--
};
}
};
let fac = 1;
let fact = 2;
factorial.seed = 7; // find the factorial of 7
while(fact > 1) {
fact = factorial.next().value;
fac *= fact;
}
console.log(fac); // 5040I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!
14
6
u/FunIsDangerous Jul 16 '21
I feel sorry for people that transcribe in this subreddit. It'd be so painful to me to actually write the code that gets posted here
14
10
15
4
2
2
1
u/dougie_cherrypie Jul 16 '21
But does this work? I feel like next() is always returning the same value because seed is not being updated.
2
u/_SYNTAX_ERROR_ Jul 16 '21
The
seed-—will decrement seed after returning the value.0
1
1
1
1
1
1
1
0
Jul 16 '21
Oof - took about lazy programming.
Factorial should have a Symbol.iterator method. And the loop should be a for-of loop instead of a while loop.
0
Jul 17 '21
[deleted]
1
u/Notimecelduv Jul 18 '21
const factorial = n => [...Array(n).keys()].reduce((acc, _, i) => acc * (i + 1), 1);
86
u/[deleted] Jul 16 '21
This is impressively roundabout