Build a Pyramid Generator - Build a Pyramid Generator

Cuéntanos qué está pasando:

El resultado es correcto, pero no paso las pruebas 3 y 4

Tu código hasta el momento

function pyramid(arg1, arg2, arg3) {
  const pyr = (numFila, arg2) => {
    return " ".repeat(arg2 - numFila) + arg1.repeat(2 * numFila - 1) + " ".repeat(arg2 - numFila);
  }
  let filas = [];

  for(let i = 1; i <= arg2; i++) {
    if (arg3){
      filas.unshift(pyr(i, arg2))
    }else {
      filas.push(pyr(i, arg2))
    }
  }

  let piramide = "";
  for(const fila of filas) {
    piramide = "\n" + piramide + fila + "\n";
  }

  return piramide;
}

console.log(pyramid("o", 4, false));


console.log(pyramid("p", 5, true));

Información de tu navegador:

El agente de usuario es: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36

Información del Desafío:

Build a Pyramid Generator - Build a Pyramid Generator

no, it’s not correct

use this:

console.log(JSON.stringify(pyramid("o", 4, false)));


console.log(JSON.stringify(pyramid("p", 5, true)));

it shows

"\n\n\n\n   o   \n  ooo  \n ooooo \nooooooo\n"
"\n\n\n\n\nppppppppp\n ppppppp \n  ppppp  \n   ppp   \n    p    \n"

this is not correct

1 Like

I thought that the result must be

   o
  ooo
 ooooo
ooooooo

that code (console.log(JSON.stringify(pyramid(“o”, 4, false))):wink: doesn’t work for me

what do you mean that it doesn’t work for you?

do you see how the strings start with four \n? check the requested output in the tests, or the user stories, that is not in the requirements

Oh! I understand.

Now I see my mistake and I passed all the tests.

Now I understand what was being asked. I guessed it and tried another way. I had the string, but it wasn’t OK. Now I do. Maybe the exercise isn’t well-expressed.