Suffix-to-E Rows in JavaScript

Beginner
⏱️ 8 min read
📚 Updated: Aug 2025
🎯 2 Code Examples
Left-strip each row

What You'll Learn

The first row is the full run AE. Each following row drops the leftmost letter: BCDE, CDE, DE, then E. The outer loop picks the starting letter; the inner loop always runs from that letter up to E.

Total letters printed is \(5 + 4 + 3 + 2 + 1 = 15 = n(n+1)/2\) for five rows.

⭐ Pattern Output

Five rows as i moves from A to E:

Output
ABCDE
BCDE
CDE
DE
E
1

Node.js / console version

Outer loop increases i from start to end; inner loop runs j from i to end:

JavaScript
const start = "A".charCodeAt(0);
const end = "E".charCodeAt(0);

for (let i = start; i <= end; i++) {
  let line = "";
  for (let j = i; j <= end; j++) {
    line += String.fromCharCode(j);
  }
  console.log(line);
}
2

Browser version (document.write)

Same logic with ASCII codes 6569. Save as .html or use the live editor:

HTML
<!DOCTYPE html>
<html>
<body>
<script>
for (let i = 65; i <= 69; i++) {
  for (let j = i; j <= 69; j++) {
    document.write(String.fromCharCode(j));
  }
  document.write("<br>");
}
</script>
</body>
</html>

🧠 How It Works

1

Outer loop: row start letter

for (let i = start; i <= end; i++) sets the first character of each row: A, then B, …, finally E.

Ascending i
2

Inner loop: through E

for (let j = i; j <= end; j++) prints forward from i to the fixed end E.

Suffix i..E
3

Line break

After each row, console.log(line) or document.write("<br>").

New row
=

Program 3, reversed order

Same inner structure as Program 3, but the outer loop direction flips which row appears first. Complexity O(n²).

💡 Tips for Enhancement

Try These

  • Compare with Program 5 (prefix shrink) side by side
  • Refactor the inner loop into a small function that builds one row from codes i through end
  • Re-read Program 3 to see the same suffix idea with a descending outer loop

Avoid

  • Starting the inner loop at A every time (that is Program 1’s growing triangle, not this pattern)
  • document.write after the document has loaded

Key Takeaways

1

Outer loop: A → E; inner loop: i → E.

2

Each row is a suffix of ABCDE.

3

Total letters: \(n(n+1)/2\).

4

Row order is the reverse of Program 3 for the same range.

5

Time complexity: O(n²).

❓ Frequently Asked Questions

Same inner loop idea (j from i to E). Program 3 decrements i from E to A, so the single-letter row prints first. Program 6 increments i, so ABCDE prints first.
Program 5 keeps a fixed left anchor at A and shortens the right end. Program 6 moves the left start rightward while keeping E on the right.
O(n²) for n rows from A to E.

Next: JavaScript Alphabet Pattern 7

Continue to the next program in the alphabet pattern series.

Program 7 →
Did you know?

If you reverse the order of the rows printed here, you get the same lines as Program 3 for AE.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

10 people found this page helpful