Skip to content

Instantly share code, notes, and snippets.

@jessecogollo
Created July 21, 2021 06:35
Show Gist options
  • Save jessecogollo/c2332b65e647daf39d20fea4b485276c to your computer and use it in GitHub Desktop.
Save jessecogollo/c2332b65e647daf39d20fea4b485276c to your computer and use it in GitHub Desktop.
Ejercicio deletreador en JavaScript
const getLetter = (word) => {
return word[0]
}
const createSinglePhrase = (word) => {
return `${getLetter(word)} is for ${word}`
}
const createPhrase = (word, lst) => {
return lst.length === 1 ?
`${createSinglePhrase(word)}, and` :
`${createSinglePhrase(word)},`
}
function deletreador(words) {
const [x, ...xs] = words
return words.length === 0 ? '' :
words.length === 1 ?
createSinglePhrase(words[0]) :
`${createPhrase(x, xs)} ${deletreador(xs)}`
}
const [_head, _second, ...words] = process.argv
console.log(deletreador(words))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment