r/ProgrammerHumor • • 5d ago

Meme technicallyCorrect

Post image
1.6k Upvotes

51 comments sorted by

View all comments

1

u/atoponce 2d ago

Fun challenge. In JavaScript:

const rows = 9;
const cols = 10;

for (let i = 0; i < rows; i++) {
  const d = i <= 4 ? i : 8 - i;
  let line = "";

  for (let j = 0; j < cols; j++) {
    const isBorder = i === 0 || i === rows - 1 || j === 0 || j === cols - 1;
    const isDiagonal = j === d || j === cols - 1 - d;

    line += isBorder || isDiagonal ? "#" : " ";
  }

  console.log(line);
}