JavaScript is really suitable for function programming because of functions being first class. Functions being first class means that JavaScript treats them as a type of object.
Functional Programming with JavaScript

Solution Architect skilled in Salesforce, NetSuite and JavaScript Development
JavaScript is really suitable for function programming because of functions being first class. Functions being first class means that JavaScript treats them as a type of object.
Arrays are usually used to store a list of elements that need to be accessed by a single variable.
I believe that to use JavaScript effectively every developer should be able to use any one of these methods on an array. These methods can save a lot of lines of codes and also allow us to do some pretty awesome function programming!
In functional programming, being able to reduce is one of the fundamental concepts.
Reduce is used to iterate through the values in an array and condense all of the values into a single value.
Usually the value is a sum of all of the elements, but it could be used to decrement, multiply or even divide.
Normally, you would want to use a reduce method when you want to sum all of the values in an array and then use the total for some operation. For example, it might make sense to use a reducer when you want to get the total number of items in a shopping cart and determine the tax or determine how many items a customer purchased.
I like using reducers to avoid having to write boiler plate code for loops and being able to do really simple one line operations.
A reduce method takes in a function as a parameter, and that function needs to take in an accumulator and the current element.
So, basically, a really simple example of how to use reduce is this:
var numberArray = [0,1,2,3] var accumulatedResult = numberArray.reduce(function (total, currentElement) { return total + currentElement; });
If we ran this in the developer console of Chrome, we would see this:
As I mentioned, every element of the array is added together and then the total is available in the accumulatedResult variable. We could write this as a for loop and get exactly the same result if we wanted to but it would be more code:
var numberArray = [0,1,2,3] var accumulatedResult = 0; for (var i = 0; i < numberArray.length; i++) { accumulatedResult += numberArray[i]; }
And, if we ran this for code for a loop in the developer console, we would see this:
So this means, that a reduce method cycles through the values in an array – in a way similar to a for loop but it’s able to do some mathematical operations like summing of values and store a lot less variables in code and use a lot less boiler plate.