post/

Crazy Times

May 7, 20221 min read

Screenshot of Crazy Times

JavaScript, Random

There are so many stars visible in New Mexico. I will walk out there to get a better look.

โ€” Werner Ziegler

const stars = generateStarPattern(3);

console.log(stars);
//   *
//  * *
// * * *

function generateStarPattern(size = 1) {
  const STAR = '*';
  const SPACE = ' ';
  const NEW_LINE = '\n';

  let stars = '';

  if (size >= 10) {
    return '๐ŸŒŒ';
  }

  for (let row = 1; row <= size; row++) {
    let paddingSize = size - row;
    let paddingCharacters = `${SPACE}`.repeat(paddingSize);
    let cellStar = `${STAR}${SPACE}`.repeat(row).trim();
    let rowStars = `${paddingCharacters}${cellStar}${NEW_LINE}`;

    stars += rowStars;
  }

  return stars;
}

License: MIT License ยท Copyright (c) 2022 Noel Earvin Piamonte

Now playing :Not playing any music.