Honestly you've given an excellent example of why "functional programming" is confusing, cryptic, and inefficient.

Particularly given how you've used .map to introduce the overhead of callbacks likely making the entire double routine take four to ten times longer than it should.

Going hand in hand with the variable-style function declaration for nothing, failure to leverage operators resulting in multiple reference accesses, etc, etc.

function double3(data) {
for (var i = 0; i < data.length; i++) data[i] *= 2;
return data;
}

Runs circles around EITHER version you have there in both performance and code clarity.

It gets worse with your “maybe” example where not only are you driving with the parking brake on in the form of .map callbacks, you run multiple calls to the painfully slow .map for ONE operation. The programming equivalent of flooring it in a front wheel drive car with the parking brake on, ripping the rear tires off and leaving grooves in the pavement from the bare metal sparking all over the place!

I’ve been programming for over four decades, and the more and more I read about “functional programming” the more and more dumbass it sounds. Maybe it’s from my starting out hand assembling my own machine language, maybe it’s that decade I spent programming in Ada, but overall this entire “functional programming” rubbish — PARTICULARLY in JavaScript — strikes me as arbitrary, pedantic, UNCLEAR, and in the process pissing on performance from orbit.

It is NOT good programming practice.

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