Last active
May 3, 2018 04:35
-
-
Save marlocorridor/631c378bee131372024400025fb4a2b6 to your computer and use it in GitHub Desktop.
Pyramid test
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 space_front(size, n) { | |
return size - n; | |
} | |
function space_mid(n) { | |
return (2 * n) - 3; | |
} | |
function is_top(n) { | |
return n > 1; | |
} | |
function asterisk() { | |
return '*'; | |
} | |
function asterisk_extra(n) { | |
return (n > 1) ? asterisk() : ''; | |
} | |
function space(n) { | |
return (n > 0) ? | |
' '.repeat(n) : ''; | |
} | |
function pyramid(size) { | |
for (var i = 1; i < size+1; i++) { | |
console.log( | |
space(space_front(size, i)) + | |
asterisk(i) + | |
space(space_mid(i)) + | |
asterisk_extra(i) + "\n" | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment