From 8e7037a2c3f94ea30bf6d1e4e29e73e440833b49 Mon Sep 17 00:00:00 2001 From: mukeunzi Date: Mon, 8 Apr 2019 21:27:08 +0900 Subject: [PATCH 1/2] step2-1 mission clear --- README.md | 2 +- area.js | 41 +++++++++++++++++++++++++++++++++++++++++ main.js | 11 +++++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 area.js create mode 100644 main.js diff --git a/README.md b/README.md index 52b046b..a65c481 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ # polygon -레벨2 +레벨2 \ No newline at end of file diff --git a/area.js b/area.js new file mode 100644 index 0000000..6965d92 --- /dev/null +++ b/area.js @@ -0,0 +1,41 @@ +const PIE = Math.PI; + +module.exports.circle = function(r){ + checkParamCount(r); + checkParamType(r); + return Math.pow(r, 2) * PIE; +} + +module.exports.square = function(a, b){ + checkParamCount(a, b); + checkParamType(a, b); + return a * b; +} + +module.exports.trapezoid = function(a, b, h){ + checkParamCount(a, b, h); + checkParamType(a, b, h); + return (a + b) * h / 2; +} + +module.exports.cylindrical = function(r, h){ + checkParamCount(r, h); + checkParamType(r, h); + return (this.circle(r) * 2) + (r * 2 * PIE * h); +} + +function checkParamType(){ + for (let i=0; i Date: Tue, 9 Apr 2019 11:36:05 +0900 Subject: [PATCH 2/2] modified facade pattern --- area.js | 41 +++++++++++++++++++++-------------------- main.js | 2 +- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/area.js b/area.js index 6965d92..c68c87e 100644 --- a/area.js +++ b/area.js @@ -1,41 +1,42 @@ const PIE = Math.PI; -module.exports.circle = function(r){ - checkParamCount(r); - checkParamType(r); +module.exports.circle = function(r = -1){ + checkParameter(r); return Math.pow(r, 2) * PIE; } -module.exports.square = function(a, b){ - checkParamCount(a, b); - checkParamType(a, b); +module.exports.square = function(a = -1, b = -1){ + checkParameter(a, b); return a * b; } -module.exports.trapezoid = function(a, b, h){ - checkParamCount(a, b, h); - checkParamType(a, b, h); +module.exports.trapezoid = function(a = -1, b = -1, h = -1){ + checkParameter(a, b, h); return (a + b) * h / 2; } -module.exports.cylindrical = function(r, h){ - checkParamCount(r, h); - checkParamType(r, h); +module.exports.cylindrical = function(r = -1, h = -1){ + checkParameter(r, h); return (this.circle(r) * 2) + (r * 2 * PIE * h); } -function checkParamType(){ - for (let i=0; i