|
|
@@ -1,10 +1,13 @@ |
|
|
|
'use strict' |
|
|
|
// rectangles |
|
|
|
|
|
|
|
function makeLine(size){ |
|
|
|
let str = ""; |
|
|
|
let counter = 0; |
|
|
|
for (; counter < size; counter++){ |
|
|
|
str += "#"; |
|
|
|
} |
|
|
|
return str |
|
|
|
return str.trim() |
|
|
|
} |
|
|
|
|
|
|
|
console.log(makeLine(5)); |
|
|
@@ -13,19 +16,67 @@ function makeSquare(size){ |
|
|
|
let counter = 0; |
|
|
|
let str = ""; |
|
|
|
for (;counter < size; counter++){ |
|
|
|
str += '\n' + makeLine(size); |
|
|
|
str += makeLine(size) + '\n'; |
|
|
|
} |
|
|
|
return str |
|
|
|
return str.trim() |
|
|
|
} |
|
|
|
|
|
|
|
console.log(makeSquare(3)); |
|
|
|
|
|
|
|
function makeRectangle(width, height) { |
|
|
|
if (height === undefined){ // of met default parameter (height = width) of logical or || --> height = height || width (als height nieg geven wordt dan wordt width gebruikt) |
|
|
|
height = width; |
|
|
|
} |
|
|
|
let counter = 0; |
|
|
|
let rec = ""; |
|
|
|
for(; counter < height; counter++){ |
|
|
|
rec += '\n' + makeLine(width); |
|
|
|
rec += makeLine(width) + '\n'; |
|
|
|
} |
|
|
|
return rec.trim() |
|
|
|
} |
|
|
|
console.log(makeRectangle(5,3)); |
|
|
|
|
|
|
|
// triangles |
|
|
|
|
|
|
|
function stairCase(n) { |
|
|
|
let stairCase = ''; |
|
|
|
for(let i = 1; i <= n; i++) { |
|
|
|
stairCase += makeLine(i) + '\n'; |
|
|
|
} |
|
|
|
return rec |
|
|
|
return stairCase.trim(); |
|
|
|
} |
|
|
|
console.log(makeRectangle(5,3)); |
|
|
|
console.log(stairCase(3)); |
|
|
|
|
|
|
|
|
|
|
|
function makeSpaceLine(numSpaces, numChars){ |
|
|
|
let str = " "; |
|
|
|
for(let i = 0; i <= numSpaces; i++){ |
|
|
|
str += " "; |
|
|
|
} |
|
|
|
return str + makeLine(numChars) + str; |
|
|
|
|
|
|
|
} |
|
|
|
console.log(makeSpaceLine(3,5)); |
|
|
|
|
|
|
|
function makeIsoclesTriangle(height){ |
|
|
|
let str = ""; |
|
|
|
for(let i = 0; i < height; i++){ |
|
|
|
str += makeSpaceLine(height - i - 1, 2 * i + 1) + '\n'; |
|
|
|
} |
|
|
|
return str.trimEnd(); |
|
|
|
} |
|
|
|
|
|
|
|
console.log(makeIsoclesTriangle(10)); |
|
|
|
|
|
|
|
|
|
|
|
function reverse(str){ |
|
|
|
return str.split('').reverse().join(''); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function makeDiamond(height){ |
|
|
|
return makeIsoclesTriangle(height) + '\n' +reverse(makeIsoclesTriangle(height)); |
|
|
|
} |
|
|
|
|
|
|
|
console.log(makeDiamond(5)); |
|
|
|
console.log(reverse(makeIsoclesTriangle(5))); |