-
Notifications
You must be signed in to change notification settings - Fork 1k
Solución Reto #44 JavaScript #1011
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| for (let index = 0; index < rawArray.length; index++) { | ||
| let auxArray = []; | ||
| if (rawArray[index] == rawArray[index + 2] && rawArray[index] != rawArray[index + 1]) { | ||
| auxArray.push(rawArray[index], rawArray[index + 1], rawArray[index + 2]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
En esta línea puedes usar Array.slice(idx, length) para capturar los tres elementos que te interesan: MDN Javascript - Array Slice. Se capturan como un subarray y los adjuntas directamente a countArray.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hola! Muchas gracias por tus comentarios.
Realice el ejercicio de esta manera debido a que se me hacia mucho mas entendible tanto para mi mismo como considere para otra persona que lo leyera. No obstante, en cuanto tenga oportunidad, hare uso de tus sugerencias para mejorar la legibilidad y reducir la cantidad de código escrito. Te agradezco las sugerencias junto a la documentación misma de cada una. Saludos!
| } | ||
| console.log("Este arreglo tiene: " + countArray.length + " Boomerangs"); | ||
| console.log("Los boomerangs son: "); | ||
| for (let index = 0; index < countArray.length; index++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
en lugar de for puedes usar forEach(elem=>console.log(elem) para listar cada uno de los bumerans. MDN Javascript - Array forEach
| countArray.push(auxArray); | ||
| } | ||
| } | ||
| console.log("Este arreglo tiene: " + countArray.length + " Boomerangs"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
puedes usar interpolación, usando backtick ` para que se vea de la siguiente manera:
console.log(`Este arreglo tiene: ${countArray.length} Boomerangs`);| * y [4, 2, 4]). | ||
| */ | ||
|
|
||
| let rawArray = [2, 1, 2, 3, 3, 4, 2, 4, 3, 3, 2, 4, 2, 6, 7, 5, 7]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haces un buen uso de nombres para las variables. definir elementos para probar tu código es una buena práctica. Le llaman TDD, Test Driven Development, pero considera varios casos.
En esta línea, como rawArray no se va a modificar, puedes definitla como const en lugar de let
Mi aporte al Reto #44 en JavaScript. Aprendiendo a usar Git de paso