Skip to content

Conversation

@DotMarcoVA
Copy link

Mi aporte al Reto #44 en JavaScript. Aprendiendo a usar Git de paso

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]);
Copy link

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.

Copy link
Author

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++) {
Copy link

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");
Copy link

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`);

Wikipedia - String Interpolation #JavaScript

* y [4, 2, 4]).
*/

let rawArray = [2, 1, 2, 3, 3, 4, 2, 4, 3, 3, 2, 4, 2, 6, 7, 5, 7];
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants