Created
March 2, 2018 08:07
-
-
Save akinjide/94ae8d417572c996c6ee248c305a7d3b to your computer and use it in GitHub Desktop.
Staircase problem implemented in JavaScript
This file contains 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
// Time Complexity O(n2) | |
const staircase = (n, c) => { | |
let y = []; | |
let s; | |
for (let i = 1; i <= n; i++) y[i - 1] = i; | |
for (let j = 1; j <= n; j++) { | |
s = y.length - j; | |
console.log(' '.repeat(s), c.repeat(j)); | |
} | |
} | |
staircase(6, '#'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment