Functional Javascript

for web-page reliability

This page is a love letter to the functional methods waiting patiently inside of Javascript. They are all ES5 array methods. All are stateless; they give predictable output. Functional programming makes the code more like math. And just as math is proveable, functional code is proveable.

I got onto this angle while using Elm, an immutable language that compiles into Javascript, providing both an immutable environment for state, as well as a pleasant encounter with your errors, via very friendly compiler error messages.

"Pure functions are easier to reason about. Testing is easier, and pure functions lend themselves well to techniques like property-based testing. Debugging is easier. Programs are more bulletproof. " - Alvin Alexander.

For each three letter prompt, can you guess the Functional javascript method? (Mouse over each for explanations.)


Remove any occurance of "never" from Lear's lament.

If the array was this

And this is the function

let sansNever =(w)=>{
if (w ==='never'){
return false;
} else if (w!=='never'){
return true;
} else {

lear_tears = bardWords.filter(sansNever);

This will be returned

Filter for The Youth in the '19 Tigers rotation.

Colors from Detroit. Data from Baseball Reference.

And this is the function

youngPitchersArrayOfObjects = rotators.filter((o)=>{return o.Age < 30 });
youngPitchersArrayOfNames =>{return o.Name} );


Join an array of words from King Lear to commentary about those words.

If the two arrays were these

And this is the function

cont = cliffWords.concat(bardWords);

This single array would be returned


Pluck several elements from the middle of an array.

If the array were this

And this is the function

cont = bardWords.slice(5, 9);

This would be returned


Convert an array to a string, optionally inserting some sort of string within its joints.

If the array were this

And this is the function

cont = lear_tears.join('****');

This would be returned

Napkin sketch

This is a mnemonic mnemonic device for remembering array functions. From the left: join, concat, slice, some(sum), every, filter, map, forEach.