Created
July 21, 2021 06:35
-
-
Save jessecogollo/c2332b65e647daf39d20fea4b485276c to your computer and use it in GitHub Desktop.
Ejercicio deletreador en JavaScript
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 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