It is a smart solution to the problem and with better formatting it would probably be better code, but with everything on one line like this it's really hard to see what is nested into what.
I used to write code like this, it looks better because it's shorter, but I learned after a while that readability is so much more important than writing short code.
I work with JS every day, and it took me some time and a lot more brainpower to read the second one.
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.
View all comments
204
u/Xuntari Apr 13 '22
It is a smart solution to the problem and with better formatting it would probably be better code, but with everything on one line like this it's really hard to see what is nested into what.
I used to write code like this, it looks better because it's shorter, but I learned after a while that readability is so much more important than writing short code.
I work with JS every day, and it took me some time and a lot more brainpower to read the second one.