Sort by

recency

|

5133 Discussions

|

  • + 0 comments

    javascript only String.repeat()

    for (let i = 1; i < n+1 ; i ++){
     console.log(" ".repeat(n-i) +"#".repeat(i));
    }
    
  • + 0 comments

    My code in JavaScript using two loop

     for (let i = n; i > 0; i--) {
            let out = "";
            for (let j = 1; j <= n; j++) {
                if (j >= i) {
                    out += "#";
                } else {
                    out += " "
                }
            }
            console.log(out)
        }
    }
    
  • + 0 comments

    Java

    String message = "";
            for(int i=1; i<=n;i++){
                message += "#";
                System.out.printf("%"+n+"s%n", message);
            }
    
  • + 0 comments

    From the problem description I thought I needed extra characters between the symbols which made my code a bit hacky and then was trying to understand/compare with the example why it was failing. When I realised it, the solution become much simpler.

    I wonder if it was just me... :D

  • + 0 comments

    My Solution in Typescript/Javascript function staircase(n: number): void {

    let space = ''
    for(let i = '#'; i.length <= n; i += '#'){
        let num = 0
        while(num < n - i.length) {
            space += ' '
            num++
        }
        space += i + '\n'    
    }
    
    console.log(space)
    

    }