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
  • Pense em qualquer número de DOIS dígitos, por exemplo 47

  • Subtraia a soma dos algarismos. Ex.: 47 - (4 + 7) = 36

  • Depois some os algarismos resultantes da subtração anterior, adicionando 4. Ex.: 3 + 6 + 4 = 13

  • Multiplique o resultado pelo inverso do número. Ex.: 13 x 31 = 403

  • E por último, multiplique por 3 o resultado anterior. Ex. 403 x 3 = 1209

  • Obs.: Qualquer número de 2 algarismos (entre 10 e 99) terão o mesmo resultado.

  • Não acredita ? Faça o teste !!!!

@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 / 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())
@lubien
lubien / excercicio.txt
Last active March 27, 2017 18:34 — forked from rafaelassumpcao/excercicio.txt
Exercicio - transformar string
Transformar uma string em outra na qual cada letra do alfabeto deve ser a proxima mantendo o resto igual. ex: a -> b, z -> a, f -> g.
Após a transformação gerar uma nova string onde toda vogal deve ser maiúscula.
exemplos:
Input:"hello*3"
Output:"Ifmmp*3"
Input:"fun times!"
@lubien
lubien / getIn.js
Created March 27, 2017 09:39
Get nested prop in JS objects
const getIn = ([prop, ...props]) => obj =>
props.length
? getIn(props)(obj[prop])
: obj[prop]
const fixture = {a: {b: {c: {d: 1}}}}
getIn(['a', 'b', 'c', 'd'])(fixture)
@lubien
lubien / is-palindrome.js
Created March 30, 2017 03:49
Is palindrome
// https://repl.it/Gln6/1
const {
length: len
, toString
, split
, join
, reverse
, take
, takeLast
@lubien
lubien / info.md
Last active March 30, 2017 03:57 — forked from Woodsphreaker/info.md

Recuperar todos os números de um array

Recupera todos arrays e retorna somente um com o valores.

No primeiro método há uma recursividade.

No segundo método, uma conversão para string, split e finalmente converte para um array final de números

Acho que pode ser útil também.

const {
identity, all, range, map, split, compose, toString
, splitAt, length: len, pipe, join, filter
} = require('ramda')
, {pow, floor} = Math
, digits = compose(map(Number), split(''), toString)
, digitsToNum = compose(Number, join(''))
, property = n => {
const
squared = pow(n, 2)