-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpattern-problem-14.js
More file actions
42 lines (38 loc) · 816 Bytes
/
pattern-problem-14.js
File metadata and controls
42 lines (38 loc) · 816 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Increasing Letter Triangle Pattern
// Input Format: N = 3
// Result:
// A
// A B
// A B C
// Input Format: N = 6
// Result:
// A
// A B
// A B C
// A B C D
// A B C D E
// A B C D E F
const pattern14 = (n) => {
// for (let i = 1; i <= n; i++) {
// let num = 'A'.charCodeAt();
// let line = '';
// for (let j = 1; j <= i; j++) {
// line += `${String.fromCharCode(num)} `;
// num += 1;
// }
// console.log(line);
// }
// Sol-2
for (let i = 0; i < n; i++) {
let line = '';
for (let ch = 'A'.charCodeAt(); ch <= 'A'.charCodeAt() + i; ch++) {
line += `${String.fromCharCode(ch)} `;
}
console.log(line);
}
};
pattern14(3);
console.log('\n=============================\n');
pattern14(6);
console.log('\n=============================\n');
pattern14(5);