-
Notifications
You must be signed in to change notification settings - Fork 37
Step2 #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Step2 #34
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7f12ccc
다각형 넓이 (#29)
HTMLhead 34304e4
modify by referring to feedback, add function getArea, add function p…
HTMLhead 271da0f
Revise var to const, Change variable name arr -> ExecutionSequenceArr…
HTMLhead 8333908
revise isNum function to use 'for' statement and add typenumberfuncti…
HTMLhead 6b42d10
modifiy function sizeCircle to CalcCircleWidth and change inner contents
HTMLhead 80712d5
Modify sizeSquare function to CalcRectWidth and change inner contents
HTMLhead e8b5434
Modify sizeTrapezoid function to calcTrapezoidWidth function and revi…
HTMLhead 69266bc
Modify sizeSylinder functino to calcSylinderWidth function and revise…
HTMLhead b16be22
Modify getArea function to check Number of arguments
HTMLhead f21a7b4
Revise little bugs,(add return to calcSylinderWidth, change some uppe…
HTMLhead File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
|
|
||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| <meta http-equiv="X-UA-Compatible" content="ie=edge"> | ||
| <title>polygon</title> | ||
| </head> | ||
|
|
||
| <body> | ||
| <h2>다각형의 넓이 구하기</h2> | ||
| <script src = 'polygonSize.js'></script> | ||
| </body> | ||
|
|
||
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| //변수 const나 let으로 변경, 변수이름 개선 | ||
| const executionSequenceArray = []; | ||
|
|
||
| //arrow함수 이용 | ||
| function printExecutionSequence() { | ||
| executionSequenceArray.forEach((v, i) => { | ||
| console.log((i + 1) + '번째 : ' + v) | ||
| }) | ||
| } | ||
|
|
||
| //1. isNum함수 개선 isNum함수를 위한 isThatNum 함수만들기 | ||
| function isNum(number1, number2, number3) { | ||
| for (let i = 1; i <= arguments.length; i++) { | ||
| if (isTypeNumber(arguments[i - 1]) === false) { | ||
| return false | ||
| } | ||
| } | ||
| return true | ||
| } | ||
|
|
||
| function isTypeNumber(number) { | ||
| return toString.call(number) === '[object Number]' | ||
| } | ||
|
|
||
|
|
||
| //2. 인자를 구분할 때 !== 를 최대한 안쓰고 단순화시키는 걸로 개선 | ||
| //3. 계산하는 함수들의 이름과 인자들의 명칭들 모두 변경 | ||
| function calcCircleWidth(radius1, radius2) { | ||
| if (radius1 > radius2) { | ||
| console.log(radius1 + '부터' + radius2 + '까지라구요? 다시 한번 생각해주세요') | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ㅋㅋ 재미있는 로깅이네요 좋아요. |
||
| return; | ||
| } | ||
| if (isNum(...arguments) && arguments.length === 1) { | ||
| const circleWidth = radius1 * radius1 * Math.PI | ||
| console.log('반지름이 ' + radius1 + '인 원의넓이는' + circleWidth + '입니다.'); | ||
| executionSequenceArray.push('circle'); | ||
| return; | ||
| } else if (isNum(...arguments) && arguments.length === 2) { | ||
| for (let i = radius1; i <= radius2; i++) { | ||
| console.log('반지름이' + i + '인 원의 넓이 : ' + (i * i * Math.PI)); | ||
| executionSequenceArray.push('circle') | ||
| } | ||
| return; | ||
| } | ||
| console.log('인자의 갯수가 맞지 않거나 숫자가 아닙니다.'); | ||
| } | ||
|
|
||
|
|
||
| function calcRectWidth(RectLowerSide, RectHeight) { | ||
| if(isNum(...arguments) && arguments.length === 2) { | ||
| const RectWidth = RectLowerSide * RectHeight | ||
| console.log('밑변이' + RectLowerSide + '높이가' + RectHeight + '인 사각형의 넓이는' + RectWidth + '입니다.'); | ||
| executionSequenceArray.push('Rect') | ||
| return; | ||
| } | ||
| console.log('인자의 갯수가 맞지 않거나 숫자가 아닙니다.') | ||
| } | ||
|
|
||
| function calcTrapezoidWidth(trapezoidLowerSide, trapezoidTopSide, trapezoidHeight) { | ||
| if(isNum(...arguments) && arguments.length === 3) { | ||
| const trapezoidWidth = (trapezoidLowerSide + trapezoidTopSide) * trapezoidHeight / 2 | ||
| console.log('밑변이 ' + trapezoidLowerSide + '아랫변이 ' + trapezoidLowerSide + '높이가 ' + trapezoidHeight + '인 사다리꼴의 넓이는 ' + trapezoidWidth + '입니다.') | ||
| executionSequenceArray.push('trapezoid'); | ||
| return; | ||
| } | ||
| console.log('인자의 갯수가 맞지 않거나 숫자가 아닙니다.') | ||
| } | ||
|
|
||
| function calcSylinderWidth (sylinderRadius, sylinderHeight) { | ||
| if(isNum(...arguments) && arguments.length === 2) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 넓이를 계산하는 함수마다 이부분이 중복이죠? isNum(...arguments) && arguments.length === 2 이런부분을 함수를 사용해서 중복을 제거할 수 있습니다. |
||
| const sylinderWidth = 2 * (sylinderRadius * sylinderRadius * Math.PI) + ((2 * Math.PI * sylinderRadius) * sylinderHeight) | ||
| console.log('반지름이 ' + sylinderRadius + '높이가 ' + sylinderHeight + '인 원기둥의 넓이는 ' + sylinderWidth + '입니다.'); | ||
| executionSequenceArray.push('sylinder'); | ||
| return; | ||
| } | ||
| console.log('인자의 갯수가 맞지 않거나 숫자가 아닙니다.'); | ||
| } | ||
|
|
||
|
|
||
| //4. 함수 인자의 갯수 확인 | ||
| function getArea(polygon, num1, num2, num3) { | ||
| if (polygon === 'circle' && arguments.length === 3) { | ||
| calcCircleWidth(num1, num2) | ||
| return; | ||
| } else if (polygon === 'rect' && arguments.length === 3) { | ||
| calcRectWidth(num1, num2) | ||
| return; | ||
| } else if (polygon === 'trapezoid' && arguments.length === 4) { | ||
| calcTrapezoidWidth(num1, num2, num3) | ||
| return; | ||
| } else if (polygon === 'sylinder' && arguments.length === 3) { | ||
| calcSylinderWidth(num1, num2) | ||
| return; | ||
| } else if (polygon === 'circle' && arguments.length === 2) { | ||
| calcCircleWidth(num1) | ||
| return; | ||
| } | ||
| console.log('인자의 갯수가 맞지 않거나 숫자가 아닙니다.') | ||
| } | ||
|
|
||
| getArea('circle', 2, 3); | ||
| getArea('rect', 2, 3); | ||
| getArea('trapezoid', 2, 3, 4); | ||
| getArea('sylinder', 2, 3); | ||
| getArea('meiv', 3, '2'); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for 문은 i++을 내가 해줘야 하는등 좀 불편한면이 있어요.
배열을 순차적으로 돌아야 하는 경우면 for-of를 사용하는 것이 이제 표준입니다.
앞으로는 for-of로 대체할 수 있을때는 for-of를 사용해보세요~