Intro to Recursion - Refactoring to a Pure Function

Share this video with your friends

Send Tweet

Our previous solution used forEach and a globally available array that could be mutated from inside our function. We can improve upon this and create a function that is easier to maintain & test by swapping our forEach loop for reduce. By removing the global array and instead making getTasks return a value directly we end up with a pure function.

Joel Hooks
Joel Hooks
~ 9 years ago

This lesson video was updated!

Bartłomiej Smykla
Bartłomiej Smykla
~ 8 years ago

In Array.prototype.reduce method, first parameter is accumulator and second one is currentValue, not previous and next.

Tre' Codez
Tre' Codez
~ 8 years ago

These three vids were the absolute best intros to Recursion I've seen in my career; for the way I see programming anyway ☻

Tre' Codez
Tre' Codez
~ 8 years ago

To me that seems like semantics.

~ 3 years ago

Really valuable, thank you