Create a cond function that takes 2 arguments:
- An matrix in the format:
[
[firstCondition, firstCallback],
[secondCondition, secondCallback],
...
]| module.exports = { | |
| async signup(name, email, password) { | |
| const exists = await models.user.findOne({ where: { email } }) | |
| if (exists) { | |
| throw new Error({ error: 'E-mail já existe. Tente se registrar com outro.' }) | |
| } | |
| const passwordEncrypted = await hashing(password) |
| const R = require('ramda') | |
| const | |
| divisibleBy = (n, x) => x % n === 0 | |
| , odd = R.compose(R.not, R.partial(divisibleBy, [2])) | |
| , fizzbuzz = x => | |
| R.ifElse( | |
| R.pipe(R.length, R.equals(0)) |
Create a cond function that takes 2 arguments:
[
[firstCondition, firstCallback],
[secondCondition, secondCallback],
...
]| /* | |
| * imap lazily maps an interable. | |
| * @param ref Either an iterable or an iterator | |
| * @param fn Map function | |
| * | |
| * It works by always returning a new iterator so that | |
| * you can chain other imaps without looping once more | |
| * over the same array! | |
| * | |
| * Since iterators are returned, to start the real mapping |
| const validPost = post => | |
| post.title && post.title.length > 10 && post.content | |
| const posts = | |
| [ {title: 'short'} | |
| , {title: 'fairly long', content: 'Foobar'} | |
| , {title: 'yet another', content: 'fixture'} | |
| ] | |
| const validPosts = posts.every(validPost) |
| const range = (start, end) => | |
| Array.from({length: end - start}, (_, i) => start + i) | |
| const divides = x => y => | |
| x % y === 0 | |
| const prime = n => { | |
| if (n < 2) | |
| return false | |
| if (n === 2) |
| const checkAndLog = x => { | |
| console.log('passed by', x) | |
| return Number.isInteger(x) | |
| } | |
| const xs = ['a', 1, 2, 3, 4] | |
| const ys = ['a', 'b', 'c', 'd', 'e'] | |
| const xsHasinteger = xs.some(checkAndLog) | |
| // passed by a |
| const checkAndLog = x => { | |
| console.log('passed by', x) | |
| return Number.isInteger(x) | |
| } | |
| const xs = [1, 2, 3, 4, 5] | |
| const ys = [6, 7, 'a', 9, 10] | |
| const areXsIntegers = xs.every(checkAndLog) | |
| // passed by 1 |
| const xs = ['a', 'b', 'c', 'd', 5] | |
| const ys = ['a', 'b', 'c', 'd', 'e'] | |
| const xsHasinteger = xs.some(Number.isInteger) | |
| const ysHasinteger = ys.some(Number.isInteger) | |
| console.log(xsHasinteger) // true | |
| console.log(ysHasinteger) // false |
| const xs = [1, 2, 3, 4, 5] | |
| const ys = [1, 2, 'a', 4, 5] | |
| const areXsIntegers = xs.every(Number.isInteger) | |
| const areYsIntegers = ys.every(Number.isInteger) | |
| console.log(areXsIntegers) // true | |
| console.log(areYsIntegers) // false |