DSA - Pattern Problem - I

DSA With JavaScript

Prerequisite:

  • Knowledge of JavaScript syntax

  • Basic understanding of for loops and while loops

Pattern

* * *
* *
*

Approach

let str = "";
for (let i = 0; i < 3; i++) {
  for (let j = 3; j > i; j--) {
    str += "*";
  }
  str += "\n";
}

console.log(str);

Output:
// ***
// **
// *