Last active
September 28, 2017 18:25
-
-
Save evaporei/8bec4f3808f8e244924c119d7a66dbe8 to your computer and use it in GitHub Desktop.
Desafios Pagar.me Ramda
This file contains hidden or 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
// link dos desafios: | |
// https://github.com/pagarme/lambda/blob/master/ramda.md#desafios | |
const { | |
add, | |
pipe, | |
prop, | |
find, | |
propEq, | |
filter, | |
propSatisfies, | |
lt, | |
map, | |
sum | |
} = require("ramda") | |
// Crie uma função "add10" que some 10 em um número. | |
const add10 = add(10) | |
console.log('add10', add10(5)) | |
// Crie uma função que receba um numero, some 30 depois multiplique o resultado por 2 | |
const double = x => x * 2 | |
const add10AndDouble = pipe( | |
add10, | |
double | |
) | |
console.log('add10AndDouble', add10AndDouble(5)) | |
// Crie uma função que receba uma transação e retorne o amount dela. | |
const transaction = { id: 12345, amount: 5000 } | |
const getTransactionAmount = prop('amount') | |
console.log('getTransactionAmount', getTransactionAmount(transaction)) | |
// Dada uma lista de transações, ache a transação com id 1337 e retorne o amount dela; | |
const transactions = [ | |
{ id: 12345, amount: 2500 }, | |
{ id: 1337, amount: 1500 }, | |
{ id: 2345678, amount: 3550 }, | |
{ id: 54321, amount: 1200 }, | |
] | |
const getTransaction1337 = pipe( | |
find(propEq('id', 1337)), | |
prop('amount') | |
) | |
console.log('getTransaction1337', getTransaction1337(transactions)) | |
// Com a mesma lista acima, crie uma função que some o amount de todas as transações com id maior que 50000 | |
const isIdGreaterThan = n => propSatisfies(lt(n), 'id') | |
const sumAmount = pipe( | |
filter(isIdGreaterThan(50000)), | |
map(prop('amount')), | |
sum | |
) | |
console.log('sumAmount', sumAmount(transactions)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment