Skip to content

Latest commit

 

History

History
52 lines (27 loc) · 1.87 KB

File metadata and controls

52 lines (27 loc) · 1.87 KB

FUNCTIONAL PROGRAMMING

Doing some research, I found functional programming concepts like immutability and pure function. Those concepts are big advantages to build side-effect-free functions, so it is easier to maintain systems — with some other benefits.

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 —

Pure functions benefits

The code’s definitely easier to test. We don’t need to mock anything. So we can unit test pure functions with different contexts:

  • Given a parameter A → expect the function to return value B
  • Given a parameter C → expect the function to return value D

Filter

Given a collection, we want to filter by an attribute. 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.

Imperative approach

An imperative way to do it with Javascript is to:
  • create an empty array evenNumbers
  • iterate over the numbers array
  • push the even numbers to the evenNumbers array

Map

The map method transforms a collection by applying a function to all of its elements and building a new collection from the returned values.


Node JS

To know more about Node JS

Click Here


Things I want to know more about

I want to know more about using node js in my webApp