Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

draw diamond in typescript

function diamond(val) {
  let y,
    w,
    shape = '';

  for (y = 0; y < val * 2 - 1; y++) {
    w = y < val ? y : val * 2 - y - 2;
    shape += Array(val - w).join(' ') + Array(w + 1).join('* ') + '*
';
  }
  console.log(shape);
}

diamond(4);
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #draw #diamond #typescript
ADD COMMENT
Topic
Name
7+8 =