#Thread
1 messages · Page 1 of 1 (latest)
Super, ya lo probé y funciona 🥳
@timid ibex Te comparto como lo hice por si quieres verlo, es lo mismo, cambia la forma de como se calculo
function createSnakeGrid(heigth, width, options = {}) {
const space = heigth * width;
for (let i = 0; i < heigth; i++) {
let print = "";
for (let j = 0; j < width; j++) {
const isOdd = !!(j % 2);
const newValue = isOdd ? (!options.reverse ? i - (heigth - 1) : -i) : i;
const value = (isOdd ? heigth * (j + 1) : j * heigth + 1) + newValue;
print += `${value >= 10 ? value : "0" + value} `;
}
console.log(print);
}
}
createSnakeGrid(5, 10, { reverse: true });