-
-
Save Matheus-de-Souza/3180e06c5005911849b7784f11e0e8fe to your computer and use it in GitHub Desktop.
Exercicio - transformar string
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
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!" | |
Output:"gvO Ujnft!" |
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 | |
pipe = (...fs) => y => fs.reduce((x, f) => f(x), y) | |
, LETTER_A = 97 | |
, LETTER_Z = 122 | |
, codeIsLetter = code => code >= LETTER_A && code <= LETTER_Z | |
, nextLetterCode = code => code == LETTER_Z ? LETTER_A : code + 1 | |
, vowel = char => ['a', 'e', 'i', 'o', 'u'].some(c => c === char) | |
, solve = str => | |
str | |
.split('') | |
.map(pipe( | |
char => char.charCodeAt(0) | |
, code => codeIsLetter(code) ? nextLetterCode(code) : code | |
, code => String.fromCodePoint(code) | |
, char => vowel(char) ? char.toUpperCase() : char | |
)) | |
.join('') | |
console.log(solve('hello*3'), solve('hello*3') === 'Ifmmp*3') | |
console.log(solve('fun times!'), solve('fun times!') === 'gvO Ujnft!') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment