Build a Pyramid Generator - Build a Pyramid Generator

Tell us what’s happening:

it seems like join is pushing the elements to the right.
i created the right spaces, how can i join my elements now to display a pyramid?

Your code so far

function pyramid(pattern, rows, downwards){
  let pyr=[];
  let stringg=pattern.repeat(1+(rows-1)*2);
  let totalLength=stringg.length;
  for (let i=rows-1; i>=0;i--){
      pyr.push(stringg.substring(stringg.length-2*i-1));
  };
  let dif=0;
  for (let j=1;j<pyr.length;j++){
    if (pyr[j]<pyr[0]){
      dif=pyr[0].length-pyr[j].length
      for (let z=0;z<dif;z++){
        pyr[j]=` ${pyr[j]} `
      }     
    }   
  }

  if (!downwards){
    pyr=pyr.reverse();

  }
  console.log(pyr)
  pyr=pyr.join('\n')
  return pyr;
}

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36

Challenge Information:

Build a Pyramid Generator - Build a Pyramid Generator

That’s strange, join method shouldn’t change anything on it own. Is there any way to confirm, whether join only joined lines together?

It seems the first for loop creates the “bricks” for the pyramid. Wich seems allright.
The second for loop is for the spacing, wich can please describe how it works?

There is a variable called totalLength wich is never used.