DEV Community

Discussion on: Daily Challenge #2 - String Diamond

Collapse
 
cvanpoelje profile image
cvanpoelje

JavaScript

diamond = width => {
  diamond = '';
  index = width * -1;
  while (index < width + 1) {
    counter = index;
    if (index < 0) {
      counter = index * -1;
    }
    diamond = diamond.concat(" ".repeat(counter + 1) + " *".repeat(width - counter)+'\n');
    index++;
  }
  return diamond;
};
console.log(diamond(6));