Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions STEP2_1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const {PI} = Math
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오 ! 디스트럭츄링~

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pow는 왜 안했어요?


function checkType(arr) {
for (let i = 0; i < arr.length; i++) {
if (typeof(arr[i]) !== "number") {
throw "please input Number data type";
}
}
}

function checkArgumentCount(arr, correctCount) {
if (arr.length !== correctCount) {
throw "please input correct number of arguments"
}
}

function circleArea(r) {
checkArgumentCount(arguments, 1);
checkType(arguments);

return PI * Math.pow(r, 2)
}

function squareArea(width, height) {
checkArgumentCount(arguments, 2);
checkType(arguments);

return width * height;
}

function trapezoidArea(x1, x2, h) {
checkArgumentCount(arguments, 3);
checkType(arguments);

return (x1 + x2) * h / 2
}

function cylinderArea(r, h) {
checkArgumentCount(arguments, 2);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이런방법이 어색하지만, 요구사항에는 맞는 방법이에요~!

checkType(arguments);

return (2 * PI * Math.pow(r, 2)) + 2 * PI * r * h
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

circleArea를 재사용할 수 있다면 더 좋을 듯.

}

console.log(circleArea(3));
console.log(squareArea(2, 7));
console.log(trapezoidArea(6, 3, 3));
console.log(cylinderArea(4, 6));