-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtriangle.ts
More file actions
91 lines (74 loc) · 1.4 KB
/
triangle.ts
File metadata and controls
91 lines (74 loc) · 1.4 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
function flipRightTriangle(n: number) {
for (let i=n-1; i>=0; i--) {
let data: any = []
for (let j=i; j>=0; j--) {
data.push("*")
}
console.log(data.join(''))
}
}
flipRightTriangle(10)
/*
[LOG]: "*****"
[LOG]: "****"
[LOG]: "***"
[LOG]: "**"
[LOG]: "*"
*/
function flipLeftTriangle(n: number) {
for (let k=0; k<n; k++) {
let temp: any = []
for (let j=1; j<=k; j++) {
temp.push(" ")
}
for (let a=n; a>k; a--) {
temp.push("*")
}
console.log(temp.join(" "))
}
}
flipLeftTriangle(5)
/*
[LOG]: "* * * * *"
[LOG]: " * * * *"
[LOG]: " * * *"
[LOG]: " * *"
[LOG]: " *"
*/
function leftTriangle(n: number) {
for (let i=1; i<=n; i++) {
let temp: any = []
for (let j=n-i; j>0; j--) {
temp.push(" ")
}
for (let k=0; k<i; k++) {
temp.push("*")
}
console.log(temp.join(""))
}
}
leftTriangle(5)
/*
[LOG]: " *"
[LOG]: " **"
[LOG]: " ***"
[LOG]: " ****"
[LOG]: "*****"
*/
function rightTriangle(n: number) {
for (let i=1; i<=n; i++) {
let data: any = []
for (let j=0; j<i; j++) {
data.push("*")
}
console.log(data.join(''))
}
}
rightTriangle(5)
/*
[LOG]: "*"
[LOG]: "**"
[LOG]: "***"
[LOG]: "****"
[LOG]: "*****"
*/