n->{int h=n+n/7,w=-~h*2+1,i=h+1,w=i*2+1,j,k=0;var o=new char[i][w];for(;i-->0;o[i][w/2]=o[i][w/2+1])for(j=w/2;j-->0;)o[i][j]=o[i][w+~j]=i<h?j<1?32:o[i+1][j-1]:" vibgyor".charAt(k++%8);return o;}
Try it online!Try it online!
n->{ // IntFunction int h=n+n/7, // Declare that height = n + n/7 w=-~h*2+1i=h+1, // that widthindex = (h+1)*2+1 h + 1 i=h+1, w=i*2+1, // that indexwidth = h + 1(h+1)*2+1 j, // j k=0; // that k = 0 var o=new char[i][w]; // Declare a 2D char array for(; // Loop i-->0; // Until i is 0 o[i][w/2]=o[i][w/2+1] // After each run, copy the middle letter. ) for(j=w/2; // Loop on j = w/2 j-->0; // Until j = 0 ) // o[i][j] // copy letters to the left side, =o[i][w+~j] // and the right side =i<h // if it's not the last line ?j<1 // if it's the first (and last) character ?32 // set it to a space. :o[i+1][j-1] // else set it to the previous character on the next line. :" vibgyor".charAt(k++%8); // else assign the next letter. return o; // return everything }
Credits