From 59e2af7540eef92b920a51a35c5abe70f893f97f Mon Sep 17 00:00:00 2001 From: Nkyo Lio Date: Mon, 29 Jun 2020 16:51:39 -0400 Subject: [PATCH 1/4] Last update --- assets/js/footer-functions.js | 2 +- assets/js/shapes.js | 46 +++++++++++++++++++++++++++++++---- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/assets/js/footer-functions.js b/assets/js/footer-functions.js index 42cc05b..a6ff491 100644 --- a/assets/js/footer-functions.js +++ b/assets/js/footer-functions.js @@ -24,7 +24,7 @@ function getBoxTests() { function getBottomLeftTriangleTests() { testGetBottomLeftTriangle("*", 1); testGetBottomLeftTriangle("*\n**", 2); - testGetBottomLeftTriangle("*\n**\n**", 3); + testGetBottomLeftTriangle("*\n**\n***", 3); } function getUpperLeftTriangleTests() { diff --git a/assets/js/shapes.js b/assets/js/shapes.js index e4351ba..c975d29 100644 --- a/assets/js/shapes.js +++ b/assets/js/shapes.js @@ -1,28 +1,64 @@ function getLine(length) { - // TODO - write method definition here + let shape = ""; + for(let i = 1; i <= length; i++) shape += "*"; + return shape; } function getBox(width, height) { - // TODO - write method definition here + let shape = ""; + for(let i = 1; i <= height; i++) { + + // Creating a new line + shape += getLine(width) + "\n"; + } + return shape; } function getBottomLeftTriangle(length) { - // TODO - write method definition here + let shape = ""; + for(let i = 1; i <= length; i++) { + shape += getLine(i); + if(i != length) shape += "\n"; + } + return shape; } function getUpperLeftTriangle(length) { - // TODO - write method definition here + let shape = ""; + for(let i = length; i >= 1; i--) { + shape += getLine(i); + if(i != 1) shape += "\n"; + } + return shape; } function getPyramid(length) { - // TODO - write method definition here + let shape = ""; + + if(length == 0 || length == 1) return getLine(length); + + for(let i = 1; i <= length; i++) { + + let line = ""; + + for(let j = 1; j <= (length - i + 1)/2; j++) { + line += " "; + } + for(let k = 1; k <= i + 2; k++) line += "*"; + + shape += line + "\n"; + } + + + + return shape; } From 710ca258565f9a217c4ac48a14bb5e6e4bfc17a5 Mon Sep 17 00:00:00 2001 From: Nkyo Lio Date: Tue, 30 Jun 2020 02:40:03 -0400 Subject: [PATCH 2/4] Last update --- assets/js/shapes.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/assets/js/shapes.js b/assets/js/shapes.js index c975d29..9046d1c 100644 --- a/assets/js/shapes.js +++ b/assets/js/shapes.js @@ -45,19 +45,26 @@ function getPyramid(length) { if(length == 0 || length == 1) return getLine(length); for(let i = 1; i <= length; i++) { - let line = ""; - - for(let j = 1; j <= (length - i + 1)/2; j++) { + for(let j = 1; j <= length - i; j++) { line += " "; } - for(let k = 1; k <= i + 2; k++) line += "*"; - shape += line + "\n"; - } + if(i == 1) { + line += "*"; + } else { + for(let j = 1; j <= 1 + Math.pow(2, i - 1); j++) { + line += "*"; + } + } + for(let j = 1; j <= length - i; j++) { + line += " "; + } - + shape += line; + if(i != length) shape += "\n"; + } return shape; } From 6377fa89b4c7669afbd4e48e929b75c35c48d279 Mon Sep 17 00:00:00 2001 From: Nkyo Lio Date: Tue, 30 Jun 2020 02:47:02 -0400 Subject: [PATCH 3/4] Last update --- assets/js/shapes.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/assets/js/shapes.js b/assets/js/shapes.js index 9046d1c..6bd9ffd 100644 --- a/assets/js/shapes.js +++ b/assets/js/shapes.js @@ -46,10 +46,13 @@ function getPyramid(length) { for(let i = 1; i <= length; i++) { let line = ""; + + // Adding leading space for(let j = 1; j <= length - i; j++) { line += " "; } + // Adding stars if(i == 1) { line += "*"; } else { @@ -58,6 +61,7 @@ function getPyramid(length) { } } + // Adding space after the stars for(let j = 1; j <= length - i; j++) { line += " "; } From 6a198849715f09152bdf44460103e42b324fafb2 Mon Sep 17 00:00:00 2001 From: Nkyo Lio Date: Tue, 30 Jun 2020 03:09:15 -0400 Subject: [PATCH 4/4] Last update --- assets/js/footer-functions.js | 4 ++-- assets/js/shapes.js | 19 +++++++++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/assets/js/footer-functions.js b/assets/js/footer-functions.js index a6ff491..9757df1 100644 --- a/assets/js/footer-functions.js +++ b/assets/js/footer-functions.js @@ -42,7 +42,7 @@ function getPyramidTests() { function getCheckerboardTests() { - testGetCheckerboard(" *\n* ", 2, 2); - testGetCheckerboard(" * \n* *\n * ", 3, 3); + testGetCheckerboard(" * \n*\n", 2, 2); + testGetCheckerboard(" * \n* *\n * \n", 3, 3); testGetCheckerboard(" * \n* *\n * \n* *\n", 3, 4); } \ No newline at end of file diff --git a/assets/js/shapes.js b/assets/js/shapes.js index 6bd9ffd..467ddfc 100644 --- a/assets/js/shapes.js +++ b/assets/js/shapes.js @@ -61,7 +61,7 @@ function getPyramid(length) { } } - // Adding space after the stars + // Adding extra space after the stars for(let j = 1; j <= length - i; j++) { line += " "; } @@ -74,5 +74,20 @@ function getPyramid(length) { function getCheckerboard(width, height) { - // TODO - write method definition here + let shape = ""; + + for(let i = 1; i <= height; i++) { + let line = ""; + for(let j = 1; j <= width; j++) { + + // Adding space or star + if((i % 2 == 0 && j % 2 == 0) || (i % 2 == 1 && j % 2 == 1)) { + line += " "; + } else { + line += "*"; + } + } + shape += line + "\n"; + } + return shape; }