Created
February 13, 2017 05:15
-
-
Save korniychuk/0b1ee119ef12d79506fcc10b7c4d2bd2 to your computer and use it in GitHub Desktop.
Drowing a rhombus using the symbol '*' in a single line
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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