Complexity is anything that makes software hard to understand or to modify.>
A pure function is a function that, given the same inputs, will always return the same outputs.
Immutable data structures are data structures that cannot be changed(mutated) after they are created. It is a powerful technique that allows us to make changes to our data structure without wiping state history. It also eliminates a whole class of nasty bugs.
What is functional programming?
Functional programming is a programming paradigm — a style of building the structure and elements of computer programs — that treats computation as the evaluation of mathematical functions and avoids changing-state and mutable data.
Note: trim: removes whitespace from both ends of a string.
pure functions + immutable data = referential transparency.
The idea of functions as first-class entities is that functions are also treated as values and used as data.
Functions as first-class entities can:
refer to it from constants and variables
pass it as a parameter to other functions
return it as result from other functions
The idea is to treat functions as values and pass functions like data. This way we can combine different functions to create new functions with new behavior.
When we talk about higher-order functions, we mean a function that either:
takes one or more functions as arguments, or
returns a function as its result.
The filter function expects a true or false value to determine if the element should or should not be included in the result collection. Basically, if the callback expression is true, the filter function will include the element in the result collection. Otherwise, it will not.
The map method transforms a collection by applying a function to all of its elements and building a new collection from the returned values.
The idea of reduce is to receive a function and a collection, and return a value created by combining the items.
Refactoring JavaScript for Performance and Readability :
Refactoring consists of improving the internal structure of an existing program’s source code, while preserving its external behavior.