Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

patterns in javascript

let n = 5; // row or column count
// defining an empty string
let string = "";

for(let i = 0; i < n; i++) { // external loop
  for(let j = 0; j < n; j++) { // internal loop
    string += "*";
  }
  // newline after each row
  string += "
";
}
// printing the string
console.log(string);


//result look like
/*

*****
*****
*****
*****
*****

*/
Comment

javascript patterns

let n = 5; // row or column count
// defining an empty string
let string = "";

for(let i = 0; i < n; i++) { // external loop
  for(let j = 0; j < n; j++) { // internal loop
    if(i === 0 || i === n - 1) {
      string += "*";
    }
    else {
      if(j === 0 || j === n - 1) {
        string += "*";
      }
      else {
        string += " ";
      }
    }
  }
  // newline after each row
  string += "
";
}
// printing the string
console.log(string);



/*

*****
*   *
*   *
*   *
*****

*/
Comment

javascript patterns

*
   **
  ***
 ****
*****
Comment

PREVIOUS NEXT
Code Example
Javascript :: convert pcap fiole to json tshark 
Javascript :: “Line Splicing in C++” 
Javascript :: jquery search button 
Javascript :: online convert javascript to typescript 
Javascript :: function x(a) vs function x(...a) the difference 
Javascript :: Creating A Promise With JSON 
Javascript :: phaser remove collider on stop 
Javascript :: create instance method javascript 
Javascript :: Creating getLastBlock Object for blockchain 
Javascript :: Executing Code When Instance Is Created 
Javascript :: Object methods + Static methods javascript 
Javascript :: javascript ls 
Javascript :: electron write to csv 
Javascript :: repeater jquery 
Javascript :: Assigning A Property The Return Value Of A Function In Class 
Javascript :: Joi conditional validation refer parent object 
Javascript :: how to skip the else statment in react tertiary 
Javascript :: JavaScript HTMLCollection Object 
Javascript :: useState intro 
Javascript :: How to Loop Through an Array with a forEach Loop in JavaScript 
Javascript :: swal on submit angular with cancel butotn 
Javascript :: javascript nodejs array to listnode 
Javascript :: selling partner api node install 
Javascript :: convert c# code to javascript 
Javascript :: electron npm start not working 
Javascript :: array methods in javascript 
Javascript :: sort list in javascript 
Javascript :: check leap year 
Javascript :: usecontext multiple provider 
Javascript :: heroku 
ADD CONTENT
Topic
Content
Source link
Name
9+2 =