Skip to content

Instantly share code, notes, and snippets.

@marlocorridor
Last active May 3, 2018 04:35
Show Gist options
  • Save marlocorridor/631c378bee131372024400025fb4a2b6 to your computer and use it in GitHub Desktop.
Save marlocorridor/631c378bee131372024400025fb4a2b6 to your computer and use it in GitHub Desktop.
Pyramid test
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