Created
April 17, 2015 20:16
-
-
Save seantunwin/60a6bcd5262b117272dc to your computer and use it in GitHub Desktop.
Output a textual pyramid
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
| /** | |
| * 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