Long-Row-First Repeats

What You'll Learn
The inner loop is the same shape as Program 9 (j from start to i), but the outer i counts down from E to A. That puts five Es on the first line, then four Ds, and so on, ending with a single A.
Total characters: \(5 + 4 + 3 + 2 + 1 = 15 = n(n+1)/2\) for five rows.
⭐ Pattern Output
Five rows from E down to A:
EEEEE
DDDD
CCC
BB
ANode.js / console version
Outer loop decreases i from end to start; inner loop runs j from start to i, printing fromCharCode(i) each time:
const start = "A".charCodeAt(0);
const end = "E".charCodeAt(0);
for (let i = end; i >= start; i--) {
let line = "";
for (let j = start; j <= i; j++) {
line += String.fromCharCode(i);
}
console.log(line);
}Browser version (document.write)
Same logic with ASCII codes 65–69. Save as .html or use the live editor:
<!DOCTYPE html>
<html>
<body>
<script>
for (let i = 69; i >= 65; i--) {
for (let j = 65; j <= i; j++) {
document.write(String.fromCharCode(i));
}
document.write("<br>");
}
</script>
</body>
</html>🧠 How It Works
Outer loop: row letter
for (let i = end; i >= start; i--) picks which letter repeats: E first, then D, …, A.
iInner loop: repeat count
for (let j = start; j <= i; j++) runs i - start + 1 times—the same inner pattern as Program 9.
jLine break
After the inner loop, console.log(line) or document.write("<br>").
Program 9, lines reversed
The five line strings match Program 9 but appear in reverse order. Complexity O(n²).
💡 Tips for Enhancement
Try These
- Contrast with Program 10: same outer
E → A, different inner bounds - One-liner row:
String.fromCharCode(i).repeat(i - start + 1) - Compare inner loop with Program 1 (there
fromCharCode(j)advances the letter)
Avoid
- Confusing with Program 10—inner
jthere runsE → i, notA → i document.writeafter the document has loaded
Key Takeaways
Outer i: E → A; inner j: A → i.
Row lengths top-to-bottom: 5, 4, 3, 2, 1.
Total characters: \(n(n+1)/2\).
Same lines as Program 9, opposite vertical order.
Time complexity: O(n²).
❓ Frequently Asked Questions
EEEEE first down to A.i from E to A. Program 10 uses inner j from E down to i (short E row first). Program 11 uses inner j from A up to i (long E row first).n rows from A to E.Next: JavaScript Alphabet Pattern 12
Continue to the next program in the alphabet pattern series.
Collect the lines from Program 9 from last to first and you get this pattern’s output for A–E.
10 people found this page helpful
