Skip to content

Instantly share code, notes, and snippets.

@korniychuk
Created February 13, 2017 05:15
Show Gist options
  • Save korniychuk/0b1ee119ef12d79506fcc10b7c4d2bd2 to your computer and use it in GitHub Desktop.
Save korniychuk/0b1ee119ef12d79506fcc10b7c4d2bd2 to your computer and use it in GitHub Desktop.
Drowing a rhombus using the symbol '*' in a single line
function rhombus(n) {
return n < 0 || n % 2 == 0 ? null :
[
(n - (n % 2)) / 2,
max => Array(max+1).fill(1).map((i, j) => ' '.repeat(max-j) + '*'.repeat(j*2+1)),
half => half.concat(half.slice(0, -1).reverse(), '').join('\n')
]
.reduce((curr, fn) => fn(curr));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment