Stunning example of what utter pointless time wasting garbage those array functions are... given you've basically turned what could be handled by one for loop without the overhead of any callbacks, into 15 system loops with 15 callbacks... much less the memory overhead of creating 17 copies of the values instead of 5.

Much less the cryptic symbol based arrow function trash where I swear, the folks working on ECMAScript won't be happy until JavaScript looks like brainf***.

Seriously is:

var by2 = [];

for (var n of anArray) if (n > 5) by2.push(n * 2);

Really so flipping hard? Much less is that callback ridden multiple methods REALLY cleaner, clearer, or simpler? BULLCOOKIES!

Also beware that the "recursive setTimeout" cannot be relied upon to accurately run every second. IF your callback takes longer than the timer granularity to execute, the next timeout will be that granularity PLUS a second. So if for example your "everySecond" cryptic arrow trash took 300ms you'd be firing every 1.3 seconds, not every second. An important and critcal difference between setTimeout, which only screws up the interval if your handler (or other tasks) adds up to more than a second.

Destructuring to get length is also pretty derp, given you're making an extra copy of the array wasting memory and processing overhead for nothing. Don't make copies of things that already exist!

I also never understood the obsession with array reversal... is "for (i = str.length - 1; i >= 0; i--)" really so hard?

Array.length assignment does a sequential update. It's faster to just discard and move the pointer with anArray = [];

etc, etc, etc...

Written by

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