Shrinking Repeat Rows

What You'll Learn
Each row repeats a single letter, but unlike Program 9 (lengths 1 … 5), lengths here go 5 … 1. The inner loop matches Program 10 (j from E down to i); only the outer loop direction differs—A through E instead of E down to A.
Total characters: \(5 + 4 + 3 + 2 + 1 = 15 = n(n+1)/2\) for five rows.
⭐ Pattern Output
Five rows from A to E:
AAAAA
BBBB
CCC
DD
ENode.js / console version
Outer loop increases i from start to end; inner loop runs j from end down to i, printing fromCharCode(i) each time:
const start = "A".charCodeAt(0);
const end = "E".charCodeAt(0);
for (let i = start; i <= end; i++) {
let line = "";
for (let j = end; 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 = 65; i <= 69; i++) {
for (let j = 69; j >= i; j--) {
document.write(String.fromCharCode(i));
}
document.write("<br>");
}
</script>
</body>
</html>🧠 How It Works
Outer loop: row letter
for (let i = start; i <= end; i++) moves from A up to E. That letter fills the row.
iInner loop: repeat count
for (let j = end; j >= i; j--) runs end - i + 1 times—the same inner pattern as Program 10.
jLine break
After the inner loop, console.log(line) or document.write("<br>").
Same lengths as Program 11
Top-to-bottom lengths are 5,4,3,2,1 like Program 11, but letters run A → E instead of E → A. Complexity O(n²).
💡 Tips for Enhancement
Try These
- Place Program 10 beside this page: same inner loop, opposite outer direction
- One-liner row:
String.fromCharCode(i).repeat(end - i + 1) - Contrast lengths with Program 9 (
1 … 5vs5 … 1)
Avoid
- Using inner
jfromAtoihere — that is Program 9 / Program 11 style, not this pattern document.writeafter the document has loaded
Key Takeaways
Outer i: A → E; inner j: E → i.
Row lengths top-to-bottom: 5, 4, 3, 2, 1.
Total characters: \(n(n+1)/2\).
Inner loop matches Program 10; outer matches Program 9’s direction.
Time complexity: O(n²).
❓ Frequently Asked Questions
EEEEE, DDDD, … (Program 11). Program 12 keeps lengths 5 … 1 but uses letters A … E on each row.i goes E → A (short row first). Program 12’s outer i goes A → E (long A row first).n rows from A to E.Next: JavaScript Alphabet Pattern 13
Continue to the next program in the alphabet pattern series.
Swapping only the outer loop between Program 10 and Program 12 swaps whether the shortest or longest repeated row prints first.
10 people found this page helpful
