Shape Rule
Descending to A
Row 0 prints EDCBA, row 1 prints DCBA, row 2 prints CBA, down to a single A on the last row.

The reverse alphabet pattern prints descending letters on each row, from a row-specific start letter down to A. This tutorial covers the shape rule, fixed top formula, reverse range step, a live preview, algorithm steps, worked JavaScript examples, edge cases, and complexity.
Descending to A
Row 0 prints EDCBA, row 1 prints DCBA, row 2 prints CBA, down to a single A on the last row.
Row index
for (let i = 0; i < rows; i++) picks the starting letter for each row — E on row 0, D on row 1, and so on.
start down to A
for (let code = start; code >= base; code--): prints descending letters from the row start down to A.
Same line / next line
Letters use line += String.fromCharCode(code); end each row with console.log(line).
1–26 rows
Pick a row count and draw the reverse descending alphabet pattern instantly in the browser.
Complexity
Total letters = n(n+1)/2; extra memory stays O(1).
A reverse alphabet pattern (EDCBA to A) prints descending letters on each row — the row start moves down while every row ends at A. With five rows the console shows EDCBA, DCBA, CBA, BA, A — the mirror of Program 6’s ascending row shape.
In JavaScript you solve it with two nested for loops: compute top = "A".charCodeAt(0) + rows - 1, set start = top - i per row, append letters with for (let code = start; code >= base; code--), then call console.log(line) for the next line.
It teaches per-row descending bounds with a fixed floor at A — the reverse-letter companion to Program 6. Once top = base + rows - 1 and code-- loops click, slice shortcuts and Program 8 follow naturally.
top = "A".charCodeAt(0) + rows - 1 — for five rows, the first row starts at E.
Row i starts at String.fromCharCode(top - i) — E, then D, then C, and so on.
for (let code = start; code >= base; code--) counts down; line += String.fromCharCode(code) then console.log(line).
Program 4 grows A, BA, CBA; this pattern shrinks EDCBA, DCBA, CBA — compare both side by side.
In short: for each row i from 0 to rows - 1, append letters from start = top - i down to A with for (let code = start; code >= base; code--) and line += String.fromCharCode(code), then call console.log(line).
Given a positive integer rows, print a left-aligned reverse alphabet pattern: each row prints descending letters from a row-specific start down to A (EDCBA when rows = 5).
# First 5 rows (conceptual shape)
# EDCBA
# DCBA
# CBA
# BA
# A | Item | Type | Description |
|---|---|---|
rows | int | Number of pattern lines to print (typically ≥ 1). |
top | int (code) | First row start letter: "A".charCodeAt(0) + rows - 1. |
| Printed output | text | Left-aligned rows; row i prints from String.fromCharCode(top - i) down to A. |
top = "A".charCodeAt(0) + rows - 1
for i from 0 to rows - 1:
start = top - i
for code from start down to A (code--):
append letter to line
log line | Approach | Idea | Best for |
|---|---|---|
| Nested reverse loops | Shrinking start + fixed floor A | Learning and interviews |
| Fixed top formula | top = "A".charCodeAt(0) + rows - 1 | This pattern — shared first-row start |
letters.slice(0, rows - i).split("").reverse().join("") | Slice prefix then reverse | Shorter production-style demos |
| Goal | Pattern |
|---|---|
| Fixed top letter | top = "A".charCodeAt(0) + rows - 1 |
| Walk each row | for (let i = 0; i < rows; i++) |
| Row start letter | start = top - i |
| Print start down to A | for (let code = start; code >= base; code--): line += String.fromCharCode(code) |
| End the row | console.log(line) |
| One-line row shortcut | console.log(letters.slice(0, rows - i).split("").reverse().join("")) |
| Ascending prefix variant | See Program 4 — rows grow A, BA, CBA |
Same EDCBA-to-A shape — two ways to think about descending row bounds.
for (let code = start; code >= base; code--)Classic charCode loop — teaches descending bounds and code--
letters.slice(0, rows - i).split("").reverse().join("")Prefix slice then reverse — compact one-liner per row
loops firstMaster nested reverse loops before the string shortcut
Reach for this pattern when teaching descending letter bounds with a fixed floor at A — the reverse-letter companion to Program 6’s ascending shape.
Natural follow-up after Program 6 — same row count, letters count down to A each row.
Practice for (let code = start; code >= base; code--) with an immediate visual check.
Combine loops with prompt() for a flexible row count.
Leads to reverse patterns, pyramids, and hollow shapes in the series.
This is a console teaching pattern — not how you build modern app screens.
Key benefit: one small program that locks in descending bounds, shrinking starts, reverse range step, output sequencing, and O(n²) thinking — the reverse-letter step after Program 6.
Choose a row count between 1 and 26 and draw the reverse descending alphabet pattern in the browser.
Three complete JavaScript programs — fixed row count, prompt input, and a letters.slice(0, rows - i) reverse shortcut. Click View Output to reveal sample console results, or Try it Yourself to run in the browser editor.
Print five rows with classic nested reverse loops — shrinking start, fixed floor A.
rows = 5Hard-coded height — ideal for first demos and screenshots.
const rows = 5;
const base = "A".charCodeAt(0);
const top = base + rows - 1; // 'E' when rows = 5
for (let i = 0; i < rows; i++) {
const start = top - i;
let line = "";
for (let code = start; code >= base; code--) {
line += String.fromCharCode(code);
}
console.log(line);
} When i = 0, start is E and the inner loop prints EDCBA. When i = 2, start is C and the row is CBA. When i = 4, start is A, so the last row is a single A. console.log(line) after the inner loop starts the next row.
Let the user choose the height at runtime.
Read the row count with prompt() and convert with parseInt() (validate with Number.isFinite in real apps).
const rowsInput = prompt("Enter the number of rows (max 26):");
let rows = parseInt(rowsInput, 10);
rows = Math.max(1, Math.min(rows, 26));
const base = "A".charCodeAt(0);
const top = base + rows - 1;
for (let i = 0; i < rows; i++) {
const start = top - i;
let line = "";
for (let code = start; code >= base; code--) {
line += String.fromCharCode(code);
}
console.log(line);
} Same charCodeAt/fromCharCode core as Example 1; only the source of rows changes. The clamp keeps letter codes within A–Z. Non-numeric input returns NaN with bare parseInt(prompt()) — validate with Number.isFinite for safer labs.
Same shape without an explicit inner letter loop.
letters.slice(0, rows - i) reversedSlice the first rows - i letters from A–Z, then reverse for each row.
const rows = 5;
const clampedRows = Math.max(1, Math.min(rows, 26));
const letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
for (let i = 0; i < clampedRows; i++) {
console.log(letters.slice(0, clampedRows - i).split("").reverse().join(""));
} letters.slice(0, rows - i) returns the first rows - i letters in ascending order. With rows = 5, row 0 is letters.slice(0, 5).split("").reverse().join("") = EDCBA, row 2 is letters.slice(0, 3).split("").reverse().join("") = CBA, and so on. Keep the two-loop version for exams that ask you to show reverse bounds and code--.
Use prompt() when reading input. Set rows (fixed or from user), clamp to 1–26, and compute top = "A".charCodeAt(0) + rows - 1.
for (let i = 0; i < rows; i++) selects the starting letter for the current line — E on row 0, D on row 1, and so on.
start = top - i then for (let code = start; code >= base; code--): prints each letter with line += String.fromCharCode(code).
console.log(line) ends the row so the next outer iteration starts fresh.
Total letters: n+(n-1)+…+1 = n(n+1)/2 — O(n²) time, O(1) extra memory.
rows = 5Trace each outer-loop value i (0-based) and see what the inner loop prints from start down to fixed A.
Outer i | start | Inner loop | Printed row | Letters this row |
|---|---|---|---|---|
0 | E | for (code = 69; code >= 65; code--) | EDCBA | 5 |
1 | D | for (code = 68; code >= 65; code--) | DCBA | 4 |
2 | C | for (code = 67; code >= 65; code--) | CBA | 3 |
3 | B | for (code = 66; code >= 65; code--) | BA | 2 |
4 | A | for (code = 65; code >= 65; code--) | A | 1 |
Total letter prints: 5 + 4 + 3 + 2 + 1 = 15 = 5×6/2. Same triangular total as Programs 1, 4, and 5 — only the letter order per row differs.
Where this reverse descending letter pattern (and its fixed floor at A) shows up beyond the homework prompt.
Clearest visual proof that for (let code = start; code >= base; code--) counts down to A while start shrinks each row.
Example: compare side-by-side with Program 4.
Natural step after Program 6 before Program 8’s fixed-top reverse variant.
Example: Program 8 ends rows at a fixed top letter.
Practice reverse character loops and line += String.fromCharCode(code)/console.log(line) with a shape that differs visibly from Program 6.
Example: compare ascending Program 6 vs this descending shape.
Swap to lowercase or digits once the letter loop works.
Example: print lowercase a..z once uppercase clicks.
Triangular totals make O(n²) concrete for beginners.
Example: count printed letters for n = 10 → 55.
Pair the pattern with Number.isFinite validation and positive-row checks.
Example: reject rows <= 0 and re-prompt.
Pro Tip: when an interviewer asks for descending letters per row, explain that start = top - i and the inner loop uses step -1 down to A.
Why this reverse descending pattern earns a spot after Program 6 in beginner JavaScript courses.
Side-by-side with Program 6 makes ascending vs descending row letters obvious.
Only loops and console output — no arrays or math libraries.
One formula change flips between Program 6’s ascending rows and this descending shape.
Streaming output needs no storage beyond loop counters.
Pro Tip: master Program 6 first, then this page — the row count is the same; only letter order and range step change.
Small habits that keep reverse alphabet-pattern code clean.
Set top = "A".charCodeAt(0) + rows - 1 before the outer loop — don’t recalculate every row.
Avoid crashes when the user types letters instead of a number.
Only call console.log(line) after the inner loop finishes the row.
for (let code = start; code >= base; code--) includes A — descending loops need an explicit negative step.
Trace rows = 3 on paper — expect CBA, BA, A — before coding larger demos.
Pro Tip: if rows print in ascending order, you almost certainly forgot step -1 in the inner range.
Mistakes that commonly break reverse descending alphabet patterns.
Counting up with code++ prints ascending letters — the pattern needs descending order.
→ Use for (let code = start; code >= base; code--) so letters count down to A.
Using code > base stops before A — the last letter on each row is missing.
→ Use code >= base so A is included on every row.
Omitting console.log(line) after the inner loop glues every letter onto one endless line.
→ Always end the row after the inner loop.
Non-numeric input returns NaN with bare parseInt(prompt()).
→ Validate with Number.isFinite and clamp range.
Program 4 prints A, BA, CBA (ascending prefix). Program 8 ends rows at a fixed top letter — not the same as EDCBA-to-A.
→ This pattern: start = top - i, for (let code = start; code >= base; code--), every row ends at A.
Check these inputs before calling the solution done.
Output is just A — start is A and the inner loop prints one letter.
Outer loop never runs — print nothing or show a message.
rows < 0Treat as invalid; re-prompt instead of silent empty output.
Output grows as n²/2 characters — fine for labs, noisy for huge n.
parseInt(prompt()) raises ValueError — validate first.
On the last row, start == base — inner loop prints one letter only.
Try these variations to lock in the reverse descending pattern.
rowsString.fromCharCode(code) with digit logicNumber.isFinite validation until rows >= 1top = "A".charCodeAt(0) + rows - 1 is computed once — for five rows the first row starts at E.for (let code = start; code >= base; code--) must include code >= base so A is included on every row.rows > 0 for interactive programs; rows = 1 should print a single A.Quick Takeaway: compute fixed top, shrink start each row, append with for (let code = start; code >= base; code--), then console.log(line).
| Program | Time | Extra space |
|---|---|---|
| Nested loops (Examples 1–2) | O(rows²) | O(1) |
letters.slice(0, rows - i).split("").reverse().join("") (Example 3) | O(rows²) | O(rows) per row string (temporary) |
The reverse alphabet pattern (EDCBA to A) is a compact bounds exercise with lasting payoff: fixed top, per-row shrinking start, reverse range, and O(n²) intuition. Master the classic two-loop version, then optionally shorten rows with letters.slice(0, rows - i).split("").reverse().join("").
Practice the three examples above, then continue to Program 8 for the fixed-top reverse variant in the series.
Every row ends at A — use for (let code = start; code >= base; code--), build with line += String.fromCharCode(code), log with console.log(line), and validate row counts when reading from prompt().
top = "A".charCodeAt(0) + rows - 1 once before the outer loopstart = top - i inside for (let i = 0; i < rows; i++)for (let code = start; code >= base; code--) and line += String.fromCharCode(code)rows ≥ 1 for interactive programsparseInt(prompt()) in Number.isFinite validation-1 on the inner rangerows = 1 edge casePrint EDCBA-to-A the beginner-friendly way.
Descending to A each row
Definitiontop = base + rows - 1
Codestart = top - i
Codefor (let code = start; code >= base; code--)
LoopO(n²) time
AnalysisEach row logs descending letters from a row-specific start down to A: top = "A".charCodeAt(0) + rows - 1, row i uses start = top - i and for (let code = start; code >= base; code--). Compare Program 4 (ascending row prefix A, BA, CBA) and Program 8 (reverse rows ending at fixed top letter).
Reverse rows ending at a fixed top letter — the next alphabet pattern in the series.
12 people found this page helpful