This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function imprima(nomeDaFuncao, saida) { | |
console.log(`${nomeDaFuncao} => ${saida}`); | |
} | |
// Crie uma função que some dois números | |
var soma = (numero1, numero2) => numero1 + numero2 | |
var resultado1 = soma(1, 3) | |
imprima('soma', resultado1) | |
// Crie uma função que verifica se um número é negativo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Boolean type coercion | |
Boolean(0) // false | |
Boolean(1) // true | |
Boolean(undefined) // ? | |
Boolean(' ') // ? | |
Boolean([]) // ? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { compose, pipe } from 'ramda' | |
const ada = { name: 'Ada Lovelace', age: 36 } | |
// getNameProp :: Object -> String | |
const getNameProp = obj => obj.name | |
// toThank :: String -> String | |
const toThank = name => `Thank you, ${name}!` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const numbers = [1, 2, 3, 4, 5] | |
const numbersMap = numbers.map | |
const double = n => n * 2 | |
const doubleNumbers = numbersMap(double) | |
// Uncaught TypeError: Array.prototype.map called on null or undefined | |
// at map (<anonymous>) | |
// at <anonymous> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Get the last element of an array | |
* @function getLast | |
* @argument {Array} arr | |
* @returns | |
*/ | |
const getLast = arr => arr.pop() | |
const numbers = [1, 2, 3, 4, 5] | |
console.log(getLast(numbers)) // => 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// increment.js | |
const increment = n => n + 1; | |
// increment.test.js | |
describe('Testing increment pure function', () => { | |
it('Incrementing 1 must to return 2', () => { | |
// O valor esperado do retorno da função increment | |
const expectedResult = 2; | |
// Passando 1 como argumento, o retorno deve ser 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// implementando operador de composição (f1 º f2)(value) | |
const compose2 = (fn1, fn2) => value => fn1(fn2(value)); | |
// Criando duas funções puras | |
const increment = (n) => n + 1; | |
const double = (n) => n * 2; | |
// Compondo duas funções puras. | |
const incrementedDouble = compose2(increment, double); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// actions.test.js | |
// Alguns imports importantes: | |
// Importando o arquivo onde terá a função acoplada à função testada | |
import * as punkapi from './path/to/file'; | |
// Importando o aquivo onde terá a função testada | |
import * as actions from './actions'; | |
// Arquivo com as constantes dos types usados nas actions | |
import * as types from './types'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// actions.test.js | |
// Importando o arquivo onde terá a função acoplada à função testada | |
import * as punkapi from './path/to/file'; | |
// Importando o aquivo onde terá a função testada | |
import * as actions from './actions'; | |
// Arquivo com as constantes dos types usados nas actions | |
import * as types from './types'; | |
// ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// actions.test.js | |
// Importando o arquivo onde terá a função acoplada à função testada | |
import * as punkapi from './path/to/file'; | |
// Importando o aquivo onde terá a função testada | |
import * as actions from './actions'; | |
// Arquivo com as constantes dos types usados nas actions | |
import * as types from './types'; | |
// ... |