-
Notifications
You must be signed in to change notification settings - Fork 98
성격 유형 검사 문제 풀이 및 README 수정 #86
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
//https://github.com/codeisneverodd/programmers-coding-test | ||
//더 좋은 풀이가 존재할 수 있습니다. | ||
|
||
//정답 1 - ssi02014 | ||
function solution(survey, choices) { | ||
const points = [3, 2, 1, 0, 1, 2, 3]; | ||
const pointBoard = { | ||
R: 0, | ||
T: 0, | ||
C: 0, | ||
F: 0, | ||
J: 0, | ||
M: 0, | ||
A: 0, | ||
N: 0, | ||
}; | ||
let result = ""; | ||
|
||
// 카테고리 별 점수 추가 | ||
for (let i = 0; i < survey.length; i++) { | ||
const categories = survey[i]; | ||
|
||
if (choices[i] < 4) { | ||
pointBoard[categories[0]] += points[choices[i] - 1]; | ||
} else if (choices[i] > 4) { | ||
pointBoard[categories[1]] += points[choices[i] - 1]; | ||
} | ||
} | ||
|
||
const pointBoardEntries = Object.entries(pointBoard); | ||
|
||
// 지표에 맞게 결과 값 도출 | ||
for (let i = 0; i < pointBoardEntries.length; i += 2) { | ||
const [curCategory, curValue] = pointBoardEntries[i]; | ||
const [nextCategory, nextValue] = pointBoardEntries[i + 1]; | ||
Comment on lines
+33
to
+35
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. "객체는 순서를 보장하지 않음" Object 객체는 순서를 보장하지 않습니다. 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. 피드백 감사합니다 말씀듣고 배열로도 좋고 Map 생성자 사용해도 좋을 것 같다는 생각이 들었네요 👍 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. '선언할 때 key가 바뀌지 않는다는 말'을 이해하지 못했어요! 다시 설명해주실 수 있나요? @ssi02014 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. 제가 알기론 ECMAScript 상의 지침이 없고, 브라우저마다 다른 것으로 알고있습니다! test 를 유사배열객체로 선언하지 않는 이상 숫자로 되어있는 key 값들도 순서의 의미를 가지지 않기 때문에, 브라우저마다 서로 다른 key 순서를 가져도 무방할 것 같습니다! 애초에 Object 의 key 값들에는 순서가 없으니까요! |
||
|
||
if (curValue < nextValue) { | ||
result += nextCategory; | ||
} else { | ||
result += curCategory; | ||
} | ||
} | ||
|
||
return result; | ||
} |
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.
"함수형 프로그래밍"
pointBoard의 키가 적기 때문에 위와 같은 방법으로 할 수 있습니다. 다만 키가 많아지는 경우 위와 같이 직접 적어주기 어렵고, 코드 또한 간결하지 않게됩니다. pointBoard를 만들기 위한 방법으로 다음과 같은 방법도 고려해보세요!
7-28라인을 아래와 같이 간단하게 나타낼 수 있습니다. 단, 모든 키값의 생성이나, 순서를 보장하지 않습니다.
Uh oh!
There was an error while loading. Please reload this page.
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.
좋은 풀이 잘봤습니다 🙇♂️ 단순 문제 요구사항에 맞추는걸 넘어서 다른 부분까지 채운 풀이를 하셨군요 👍
정말 깔끔하네요 도움이 많이 됐습니다 그런데 이번처럼 깔끔하게 나오는거 제외하고 가끔 저는
명령형
이 오히려 가독성이 좋을 때도 있어서 꼭선언형(함수형)
처럼 작성해야되냐?는 고민이 좀 되네요 🤔 어떻게 생각하시나요??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.
동의합니다! 명령형이 오히려 가독성이 좋을때도 있다고 생각해요 😄
하지만 대부분의 경우 함수형(선언형 프로그래밍의 일종)이 더 가독성이 좋을 때가 많다고 생각해요! 명령형은 코드의 흐름이 길어질 수록 파악하기 어려운 경우가 많은 것 같습니다.
함수형의 가독성이 떨어지는 경우는 고차함수에 대한 이해도가 부족한 것에서 오는 경우가 많은 것 같아요!
프론트엔드를 희망하고 계신다면 함수형으로 작성해야할 경우가 많기 때문에 저는 함수형으로 최대한 풀어보려고 노력하고 있습니다!!
코테를 볼 때는 생각이 잘 안나서 명령형으로 풀 때도 있지만, 리팩토링 할 때는 반드시 함수형으로 바꾸려 노력하는 편이에요 👍