Forked from rafaelassumpcao/gist:5a219be0fbf97e2d966def2083a3df91
Last active
March 20, 2017 18:08
-
-
Save lubien/2bd6a8bfaeb3625d4ec1c31953a19578 to your computer and use it in GitHub Desktop.
Excercicio
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
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^&" |
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 | |
c = (...fs) => y => fs.reduceRight((x, f) => f(x), y) | |
, len = x => x.length | |
, maxBy = f => (x, y) => f(x) > f(y) ? x : y | |
, reduce = f => xs => xs.reduce(f) | |
, words = str => str.match(/(\w|[^\x00-\x80])+/g) | |
, MaiorPalavra = c(reduce(maxBy(len)), words) | |
console.log(MaiorPalavra('Olá mundo')) | |
console.log(MaiorPalavra('Letra após letra')) | |
console.log(MaiorPalavra('uma confusa /:cadeia de caracteres:/[ isso não é!!!!!!!~')) | |
console.log(MaiorPalavra('uma bonita sequência^&')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment