Skip to content

Instantly share code, notes, and snippets.

@tgmarinho
Created July 6, 2018 04:20
Show Gist options
  • Select an option

  • Save tgmarinho/9da715c1f21e8d9ebe23d7282c74fd9b to your computer and use it in GitHub Desktop.

Select an option

Save tgmarinho/9da715c1f21e8d9ebe23d7282c74fd9b to your computer and use it in GitHub Desktop.
exercitando recursão
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