r/badcode • u/WreckerOfAll • Jan 24 '22
js I apologize to mobile users (all users actually) in advance. See comments for expanded code and explanation.
506
Upvotes
r/badcode • u/WreckerOfAll • Jan 24 '22
61
u/WreckerOfAll Jan 24 '22 edited Jan 24 '22
Here is the expanded code.
The line is implemented in a RESTful JS server to catch any missing parameters in the request. Although I have many 'one-lined' functionalities in my code, this is by far the most heinous.
Edit: Moved link from PB to Carbon, implemented change suggested by u/WalditRook
269
u/tadbolmont Jan 24 '22
I don't even want to try to understand this SINGLE LINE of code.
58
u/onichama Jan 24 '22 edited Jan 24 '22
Image Transcription: Code
I'm a human volunteer content transcriber and you could be too! If you'd like more information on what we do and why we do it, click here!
9
u/RolyPoly1320 Jan 24 '22
Is this something that could have been validated on the client side but was instead done on the server for some reason?
6
u/wolderado Jan 24 '22
You need at least two widescreen monitors to fit that beast
5
u/maxximillian Jan 24 '22
I accept that the 80 char line limit is archaic and a relic of an world that doesnt exists anymore. All that said this is why we have code reviews and social shaming
5
u/augenvogel Jan 24 '22
Always make sure, that your js code is directly obfuscated while coding it. The more arrow functions the better the code. JS Code needs to be as complicated to look at as possible.
4
u/Tomekske Jan 24 '22
I found a bug on line 34
4
u/trutheality Jan 24 '22
Just proof that you can code perfectly functional JS with a broken Enter key.
2
u/Will_i_read Jan 24 '22
That's why extra wide monitors exist.
2
u/publicOwl Jan 24 '22
Ah, chode code. I hate this, thank you.
2
u/killersquirel11 Jan 24 '22
Why waste time write many line when one do trick?
3
u/thisuseridisnttaken Jan 24 '22
Not only is it chaos as a one liner, but it is inefficient as a solution for what is needed here since it will always iterate through the array twice. (2n, where n is number of keys).
For optimising or future reference, any instance you need to do a filter and a map, one after the other, it is better to combine the logic within a reduce instead - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce.
1
u/[deleted] Jan 24 '22
Option + Z that shit
1
u/Lovexxy Jan 24 '22
AHHHHHHHHHHHHHHHHHHHHHHH
1
u/Soundwave_47 Jan 24 '22
This almost crashed Relay for Reddit. Well done, sir.
1
u/thebritisharecome Jan 24 '22
I vote we offer OP up as a sacrifice we need to stop this oneliner craze
1
u/dndai Jan 25 '22
Top answers on codewars are like this.
1
u/ilyash Jan 25 '22
When your IDE can't do code formatting.
1
u/Old-Yogurtcloset-629 Jan 04 '23
tbh, i try to write such code as much as possible, it makes me feel superior somehow, if i can write list compressions with thousands of characters in one line, than forget how it works and just hope for it to still work..
1
u/KseandI Jan 24 '22 edited Jan 24 '22
Functional programming be like:
Edit: Nobody saw the joke, so "/j"
1
u/[deleted] Jan 24 '22
Pretty cool code actually in my opinion. The only thing I noticed was the oneliner part of it. Formatting and 👍🤙