Split Descending + Ascending

What You'll Learn
This pattern builds each row by combining two parts: first a descending sequence from the row letter down to B, then an ascending sequence from A up to the row letter. That creates rows like CBABC and EDCBABCDE.
⭐ Pattern Output
A
BAB
CBABC
DCBABCD
EDCBABCDENode.js / console version
Two loops per row: descending then ascending.
const A = "A".charCodeAt(0);
const top = "E".charCodeAt(0);
for (let i = A; i <= top; i++) {
let line = "";
for (let j = i; j > A; j--) line += String.fromCharCode(j);
for (let j = A; j <= i; j++) line += String.fromCharCode(j);
console.log(line);
}Browser version (document.write)
Matches the reference: write characters directly, then a line break.
<!DOCTYPE html>
<html>
<body>
<script>
const A = 65;
const top = 69;
for (let i = A; i <= top; i++) {
for (let j = i; j > A; j--) document.write(String.fromCharCode(j));
for (let j = A; j <= i; j++) document.write(String.fromCharCode(j));
document.write("<br>");
}
</script>
</body>
</html>🧠 How It Works
Core idea
Outer i runs from A to E. First inner loop prints descending letters from i down to just above A, then the second inner loop prints ascending letters from A to i. This makes rows like DCBABCD.
Loops + condition
An outer loop picks the row, inner loop(s) decide what to print (letter / star / blank) based on comparisons.
Connect it to the output
Compare each loop boundary with the pattern output above — each row corresponds to one outer iteration.
Key Takeaways
Descending part: i..B (skip A).
Ascending part: A..i (includes A).
This avoids duplicating A in the center.
Time complexity: O(n²).
❓ Frequently Asked Questions
document.write("*") (or string concatenation) between prints, or build an array and join.More JavaScript alphabet patterns
Browse the full list for more variations.
These patterns are great practice for combining two loops to build a single row string.
10 people found this page helpful
