Skip to content

Instantly share code, notes, and snippets.

View lubien's full-sized avatar
💭
Teaching people 🔥🦩 LiveView 🔥🦩

Lubien lubien

💭
Teaching people 🔥🦩 LiveView 🔥🦩
View GitHub Profile
@lubien
lubien / show-me.js
Last active March 14, 2017 17:26 — forked from ronaiza-cardoso/show-me.js
Show Me the Evens - Show me the Odds
/**
* Show Me the Evens - Show me the Odds
* Diana is learning to count and she just learned the difference between odds and even numbers.
* She wants to have some fun, so she picks a random number.
* If that number is even, she decides to count all the even numbers up to it starting from 0 up to (but not including) the input.
* If not, she decides to count all the odd numbers up to that number starting from 1 (but not including) the input.
**/
const
range = x => y =>
@lubien
lubien / primeNumbers.js
Last active March 14, 2017 19:40 — forked from Woodsphreaker/primeNumbers.js
Dado um número aleatório, retornar todos os números PRIMOS entre 0 e o número escolhido
const
range = x => y =>
Array.from({length: y - x})
.map((_, i) => x + i)
, {ceil, sqrt} = Math
, lt = y => x =>
x < y
@lubien
lubien / operators.js
Last active March 16, 2017 20:03 — forked from Woodsphreaker/operators.js
Basic Operators Challenge
const
composeN = (...fs) => y =>
fs.reduceRight((x, f) => f(x), y)
, concat = ys => xs =>
xs.concat(ys)
, flatten = xs =>
reduce(uncurry2(concat))(xs)
@lubien
lubien / matrix-multiplication.js
Last active March 18, 2017 14:23
Multiply two matrices
const
id = x =>
x
, always = x => () =>
x
, not = prop =>
!prop
@lubien
lubien / ascend.js
Last active March 18, 2017 23:46
Given an index `n` and an array, return a new array with the nth value on the head
const clamp = l => h => x =>
x > h
? h
: x < l
? l
: x
const
ascend = i => xs => {
let
@lubien
lubien / reduce-max.js
Created March 20, 2017 16:58
Find the max number in an array using reduce
const max = (x, y) => x > y ? x : y
console.log([1, 2, 3, 4, 5, 6].reduce(max))
@lubien
lubien / reduce-max-by.js
Last active March 20, 2017 17:09
Find the max number in an array using reduce and maxBy
const len = x => x.length
const maxBy = fn => (x, y) => fn(x) > fn(y) ? x : y
console.log(['a', 'ab', 'abc'].reduce(maxBy(len)))
crie uma função chamada MaiorPalavra(str) que recebe um parâmetro do tipo string e retorna a maior palavra.
tenha como casos de entrada os exemplos abaixo:
"Olá mundo"
"Letra após letra"
"uma confusa /:cadeia de caracteres:/[ isso não é!!!!!!!~"
"uma bonita sequência^&"
@lubien
lubien / negative-number-matrix.js
Last active March 21, 2017 00:09 — forked from ronaiza-cardoso/negative-number-matrix.js
Count Negative Integers in Matrix
const
composeN = (...fs) => y =>
fs.reduceRight((x, f) => f(x), y)
, flatten = xs =>
xs.reduce((acc, x) => acc.concat(x))
, filter = pred => xs =>
xs.filter(pred)
@lubien
lubien / Poller.js
Created March 22, 2017 18:54
Execute operations with delay time between them
const Poller = (time, callback) => {
const queue = [];
const add = op => {
queue.push(op)
}
const exec = () => {
callback(queue.shift())