Skip to content

Instantly share code, notes, and snippets.

@pepperbob
Created November 7, 2020 21:58
Show Gist options
  • Select an option

  • Save pepperbob/8d9665355c3ccadaf2888400eca3e935 to your computer and use it in GitHub Desktop.

Select an option

Save pepperbob/8d9665355c3ccadaf2888400eca3e935 to your computer and use it in GitHub Desktop.
diamonds #
const H = 13;
const P = (H - 1) / 2;
const idx = (curr) => (curr - Math.max(0, 2 * (curr - P)));
const r = [...Array(H).keys()]
.map(idx)
.map(i => {
// any shorter?
const line = [..." ".repeat(H)];
line[P-i] = "#";
line[P+i] = "#";
return line.join("");
})
.join("\n");
console.log(r);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment