r/badcode • • Apr 13 '22

js Found this monstrosity while refactoring some of my old code

Post image
208 Upvotes

85 comments sorted by

View all comments

Show parent comment

13

u/Lonewolf953 Apr 13 '22 edited Apr 13 '22

funnily enough it was the opposite for me, in the old code I'm still trying to figure out why certain if statements are there to begin with

meanwhile the new code only took me a few seconds to understand, I guess it comes down to how familiar one is with modern JS code

EDIT: all I did was say I understood the new code faster than the old code and I got downvoted, don't give any opinions on reddit, what a surprise..

15

u/Xuntari Apr 13 '22

A lot of it comes down to personal preference I suppose, but the consensus seems to be that nesting like this on one line is hard to read.

I agree that the solution is better, but i would split it up more, into multiple variables with good names, to avoid the nesting and make it more apparent what each step does.

0

u/[deleted] Apr 13 '22

[deleted] — view deleted comment

1

u/AdminYak846 Apr 15 '22

I work with JS and map and filter are fine, its reduce that trips me up constantly.