Created
July 6, 2018 04:20
-
-
Save tgmarinho/9da715c1f21e8d9ebe23d7282c74fd9b to your computer and use it in GitHub Desktop.
exercitando recursão
This file contains hidden or 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 name = "thiago marinho" | |
| const findLetterInName = (name = 'João', letter = 'j') => { | |
| const [head, ...tail] = name.toLowerCase().trim().split(''); | |
| return (head === letter.toLowerCase()) | |
| ? 'gotcha: ' + head | |
| : tail.length > 0 | |
| ? findLetterInName(tail.join(''), letter ) | |
| : 'no results for: ' + letter | |
| } | |
| console.log(findLetterInName(name, 'a')) | |
| let results = findLetterInName() | |
| // let teste = letras.map(item => { | |
| // return (item === letra) ? 'achou' : 'nao achou' | |
| // }) | |
| // console.log(teste) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment