We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Loading...
  • Practice
  • Compete
  • Jobs
  • Leaderboard
  • Hiring developers?
  1. Practice
  2. Algorithms
  3. Warmup
  4. Staircase
  5. Discussions

Staircase

  • Problem
  • Submissions
  • Leaderboard
  • Discussions
  • Editorial

    You are viewing a single comment's thread. Return to all comments →

  • vm95604b 3 years ago+ 2 comments

    var i = 1;

    while (i <= n) {

    console.log( " ".repeat( n-i ) + "#".repeat( i ) );

    i++;

    }

    I just did it with this.

    0|
    ParentPermalink
    • falk_schwiefert 3 years ago+ 1 comment
      for (var i = 1; i <= n; i++) {
          console.log(' '.repeat(n - i) + '#'.repeat(i));
      }
      
      7|
      ParentPermalink
      • phqs_phqs 3 years ago+ 1 comment

        I did that way. Using only 3 lines of code is definitely a better approach, but I wanna share my code with you guys.

        for(i = 0; i < n; i++){
          var output = "";
          for(j = n; j > 0; j--){
        	if(i < j - 1){
        	output+=" ";
        	}else{
        	output+="#";
        	}
          }
          console.log(output);
        }
        
        2|
        ParentPermalink
        • marmarm 3 years ago+ 0 comments

          This is the solution I personally tried and failed to create :P

          0|
          ParentPermalink
    • cnps_bjjfan 10 months ago+ 0 comments
      let lineToPrint = '';
      for (let i = 0; i < n; i++) {
          lineToPrint += '#';
          console.log(' '.repeat((n - i) - 1) + lineToPrint);
      }
      
      0|
      ParentPermalink
  • Contest Calendar
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature