forked from LaunchCodeEducation/javascript-projects
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction-exercises.js
More file actions
78 lines (67 loc) · 2.11 KB
/
function-exercises.js
File metadata and controls
78 lines (67 loc) · 2.11 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
function makeLine(lineSize) {
let diamondOutput = "";
for (let i=0; i<lineSize; i++) {
diamondOutput = diamondOutput + "#";
}
return diamondOutput;
}
function makeSquare(SquareSize) {
let squareOutPut = makeRectangle(SquareSize,SquareSize);
return squareOutPut;
}
function makeRectangle(rectWidth, rectHeight) {
let rectangleOutPut = "";
for (let i = 0; i<(rectHeight-1); i++) {
rectangleOutPut = rectangleOutPut + makeLine(rectWidth) + '\n';
}
if (rectHeight>0) {
rectangleOutPut = rectangleOutPut + makeLine(rectWidth);
}
return rectangleOutPut;
}
function makeDownwardStairs(stairHeight) {
let stairOutput = "";
for (let i=0; i<stairHeight; i++){
stairOutput = stairOutput + makeLine(i+1);
if ((i+1)<stairHeight) {
stairOutput = stairOutput + '\n';
}
}
return stairOutput;
}
function makeSpace(spaceLength, spaceIcon = ' ') {
let spaceOutput = ""
for (let i=0;i<spaceLength;i++){
spaceOutput = spaceOutput + spaceIcon;
}
return spaceOutput;
}
function makeSpaceLine(spaceNum,hashNum, hashIcon = '#', spaceIcon = ' ') {
let spaceLineOutput = "";
let spacesTemp = makeSpace(spaceNum, spaceIcon);
for (let i=0;i<hashNum;i++){
spaceLineOutput = spaceLineOutput + hashIcon;
}
spaceLineOutput = spacesTemp + spaceLineOutput + spacesTemp;
return spaceLineOutput;
}
function makeIsocelesTriangle(isoHeight, hashIcon = '#', spaceIcon = ' '){
let isoOutput = "";
for (let i=0; i<isoHeight; i++) {
isoOutput = isoOutput + makeSpaceLine((isoHeight-(i+1)),(2*i+1), hashIcon, spaceIcon);
if (i<(isoHeight-1)){
isoOutput = isoOutput + "\n";
}
}
return isoOutput;
}
function makeDiamond(diaHeight, hashIcon = '#', spaceIcon = ' ') {
let diaTemp = makeIsocelesTriangle(diaHeight, hashIcon, spaceIcon);
let diaOutput = diaTemp;
diaOutput = diaOutput + '\n' + reverse(diaTemp);
return diaOutput;
}
function reverse(inputString) {
return inputString.split('\n').reverse().join('\n');
}
console.log(makeDiamond(48,'v',','))