Created
February 18, 2021 11:21
-
-
Save ramirodoninodev/1a782b3e47965191516d32b8e57f21c7 to your computer and use it in GitHub Desktop.
Función que devuelve un objeto con la cantidad de palabras con A y el total de palabras.
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
| function cuentaPalabras(text){ | |
| const cantidadDePalabras = text.split(" "); | |
| var palabrasConA = 0; | |
| for(i = 0; i < cantidadDePalabras.length; i++){ | |
| palabraAEvaluar = cantidadDePalabras[i] | |
| if(palabraAEvaluar[0] == "a"){ | |
| palabrasConA ++ | |
| } | |
| } | |
| const obj = { | |
| cantidadDePalabras: cantidadDePalabras.length, | |
| palabrasConA: palabrasConA | |
| } | |
| return obj | |
| } | |
| // no modificar esta funcion | |
| function testCuentaPalabras() { | |
| const texto = | |
| "Lorem ipsum dolor sit amet consectetur adipisicing elit. Iste temporibus non, eligendi harum adipisci eos provident quaerat eveniet illo placeat distinctio omnis pariatur maiores et voluptates perferendis laborum quam facere."; | |
| const resultado = cuentaPalabras(texto); | |
| if (resultado.cantidadDePalabras == 30 && resultado.palabrasConA == 3) { | |
| console.log("testCuentaPalabras passed"); | |
| } else { | |
| throw "testCuentaPalabras falló"; | |
| } | |
| } | |
| function main() { | |
| testCuentaPalabras(); | |
| } | |
| main(); |
Author
Buen día Ramiro! Para mi el código esta bien. Saludos
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Estas seguro q esto es para mi ?? Porque utilizo function, split en el codigo. Solo escribi en español lo q me pidio marce. Me parece raro eso nomas ja. Gracias por el review