Your entire first example is a stunning example of using JavaScript to do things that are NONE of JavaScript's flipping business. Unless you're correcting broken issues like CSS transitions not being able to do a dimension change from 0 to auto, if you're screwing around with style in your scripting you're doing it all wrong!

But I guess that should be expected from the use of the derpy const for nothing, the painful overhead of forEach, the needlessly cryptic arrow function trash, the use of if/else to do switch/case's job, the slow and cryptic "template string" garbage, and the rest of the bad practices that are all hot and trendy right now thanks to pointlessly cryptic and uselessly redundant additions that have been made to the language.

But then since you don't seem to ACTUALLY be working with a DOM or walking it, instead going full Gungan with using arrays and array-likes, this can hardly be a shock either.

Not sure what exactly that code is supposed to be accomplishing, but I'm pretty sure it's a convoluted over-thought mess.

I mean if it's actually a DOM element, walk the DOM!

function walkDOM(element, callback) {
callback(element);
if (element.firstChild) walkDOM(element.firstChild, callback);
while (element = element.nextSibling) walkDOM(element, callback);
} // walkDOM

THAT’S the power of recursion with using the DOM properly.

Again though, I can’t even figure out what that mess in your first section is even trying to accomplish… I’m just certain it’s not something JavaScript should even be doing since it looks like it’s pissing on the DOM with style. We have stylesheets for a reason, use them.

And again I see that bizzaro Object.keys with foreach trash. Can anyone explain to me why you’d waste memory and processing time that way over a conventional for loop? Particularly if you’re doing key-based in which case for/in would actually be FASTER and less code?!?

Seriously, what is that garbage and why is it so hot and trendy right now? Just TRYING to make the code less clear and less efficient?

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store