r/badcode • • Jul 16 '21

js f-fa-fac-fact-facto-factor-factori-factoria-factorial

Post image
734 Upvotes

42 comments sorted by

86

u/[deleted] Jul 16 '21

This is impressively roundabout

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

u/[deleted] 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.

1

u/dydzio Jul 16 '21

I found programming IRC channels to be far better than stack overflow tbh

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

u/[deleted] 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

u/anyfactor Jul 16 '21

ra ra rasputin

3

u/BarsikWasTaken Jul 16 '21

Ga ga uh la la

47

u/rcmaehl Jul 16 '21

C-c-c-chia

14

u/[deleted] Jul 16 '21

Damnit now I have that jingle stuck in my head.

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); // 5040

I'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

u/weefuckingwoo Jul 16 '21

good human

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

u/skhoyre Jul 16 '21

Fa-fa-fa-fa-fa-fa-fa-fa-fa-far better

6

u/DrKapow Jul 16 '21

Run, run, run, run, run, run, run, away

10

u/IchBinDieMadness Jul 16 '21

constant fact does't care about your feelings 😎😎

15

u/[deleted] Jul 16 '21

I need to unsub so I don’t get unreasonable furious in the middle of the day

4

u/UltraPoci Jul 16 '21

Destroyed with fac, fact, factorial and logic

2

u/[deleted] Jul 16 '21

Oh fac this

2

u/badlight27 Jul 16 '21

what the fack

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

u/dougie_cherrypie Jul 16 '21

Ok, I didn't know about that syntax, thanks

1

u/brdzgt Jul 18 '21

Not to bash on you, but incrementation is a pretty basic operation

1

u/Satyam7166 Jul 16 '21

Professor Quirrel?

1

u/CopperyMarrow15 Jul 16 '21

and that's a fact

oh wait it's a fac

1

u/CSsharpGO evil Jul 16 '21

And that’s a fact(orial).

1

u/[deleted] Jul 16 '21

what the fuck is this code

1

u/phnomet Jul 16 '21

Wat the fac

1

u/Taksin77 Jul 16 '21

I was expecting factorio...

1

u/badrumme Jul 20 '21

fac fac fac fac FACKING FACTORIAL

0

u/[deleted] 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

u/[deleted] Jul 17 '21

[deleted]

1

u/Notimecelduv Jul 18 '21
const factorial = n => [...Array(n).keys()].reduce((acc, _, i) => acc * (i + 1), 1);