Skip to content

Instantly share code, notes, and snippets.

@seantunwin
Created April 17, 2015 20:16
Show Gist options
  • Select an option

  • Save seantunwin/60a6bcd5262b117272dc to your computer and use it in GitHub Desktop.

Select an option

Save seantunwin/60a6bcd5262b117272dc to your computer and use it in GitHub Desktop.
Output a textual pyramid
/**
* Create a pyramid
* @uses pyramid(<Number:Integer>)
* @var steps: [Number:Int] Number of pyramid steps
* @returns String
*
* @example:
* console.log(pyramid(6));
* Outputs:
* #
* ###
* #####
* #######
* #########
* ###########
**/
function pyramid(steps) {
var a = ' '
, b='#'
, c = steps
, d = c
, e = ''
, f = '\n';
while (c > 0) {
e += (c < d) ? Array(3).join(b) : b;
f += Array(c).join(a);
f += e + '\n';
c--;
}
return f;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment