# Logic Programming

`Logic programming is a type of programming paradigm which is largely based on formal logic. Any program written in a logic programming language is a set of sentences in logical form, expressing facts and rules about some problem domain.. (Wikipidia)`

https://en.wikipedia.org/wiki/Logic_programming

``````function isOlder(age) {
if (age >= 18) {
return true
} else {
return false
}
}``````

# Functional Programming

`In computer science, 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. (wikipedia)`

https://en.wikipedia.org/wiki/Functional_programming

# Functional programming you need lees code

``````
const animals = [
{ name: "Toto", species: "dog"},
{ name: "Bidu", species: "dog"},
{ name: "Mial", species: "cat"},
{ name: "Garfield", species: "cat"},
{ name: "Ze", species: "parrot"},
]

var isDog = function(animal) {
return animal.species === "dog"
}

var isCat = function(animal) {
return animal.species === 'cat'
}

var dogs = animals.filter(isDog)
var cats = animals.filter(isCat)

console.log(dogs)
console.log(cats)
``````

# Features FP

• ### Recursion

``````const animals = [
{ name: "Toto", species: "dog"},
{ name: "Bidu", species: "dog"},
{ name: "Mial", species: "cat"},
{ name: "Garfield", species: "cat"},
{ name: "Ze", species: "parrot"},
]

var isDog = function(animal) {
return animal.species === "dog"
}

isDog(animals[3])  //return is true
``````

# First-Class

``````const animals = [
{ name: "Toto", species: "dog"},
{ name: "Bidu", species: "dog"},
{ name: "Mial", species: "cat"},
{ name: "Garfield", species: "cat"},
{ name: "Ze", species: "parrot"},
]

// isDog is a function
// [].filter() is a function

animals.filter(isDog)
/*
return [
{ name: "Toto", species: "dog"},
{ name: "Bidu", species: "dog"}
]
*/``````
``````function sum(n1, n2) {
return n1 + n2
}

sum(1,1) // 2``````