-
Notifications
You must be signed in to change notification settings - Fork 98
[2022.04.26] level2 - 예상대진표 풀이 추가 #44
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 | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -13,3 +13,30 @@ function solution(n, a, b) { | |||||||||||||
} | ||||||||||||||
return currentRound | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
//정답 2 - le2sky | ||||||||||||||
function solution(n, a, b) { | ||||||||||||||
let arr = Array.from({ length: n }, () => 0) | ||||||||||||||
arr[b - 1] = "B" | ||||||||||||||
arr[a - 1] = "A" | ||||||||||||||
|
||||||||||||||
const isDiff = () => { | ||||||||||||||
return ( | ||||||||||||||
(arr.indexOf("A") + 1 > arr.length / 2 && arr.indexOf("B") + 1 <= arr.length / 2) || | ||||||||||||||
(arr.indexOf("A") + 1 <= arr.length / 2 && arr.indexOf("B") + 1 > arr.length / 2)) ? true : false | ||||||||||||||
}; | ||||||||||||||
const isLeft = () => { | ||||||||||||||
return (arr.indexOf("A") + 1 > arr.length / 2) ? false : true | ||||||||||||||
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. 🌱 반영해도 좋고 넘어가도 좋아요. 🌱 이전 코멘트와 동일하게 불필요한 boolean 값들을 제거하시면 더 좋을 것이라 생각합니다!
Suggested change
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. 이 생각은 전혀 못했었네요 항상 좋은 리뷰 감사드립니다! ㅎㅎ |
||||||||||||||
}; | ||||||||||||||
|
||||||||||||||
//대진표의 절반을 기준으로 양옆에 A와 B가 있을 경우 log2N을 구하면 라운드 수가 나옴 | ||||||||||||||
while (!isDiff()) { | ||||||||||||||
if (isLeft()) { | ||||||||||||||
arr.splice(arr.length / 2) | ||||||||||||||
} else { | ||||||||||||||
arr.splice(0, arr.length / 2) | ||||||||||||||
} | ||||||||||||||
Comment on lines
+34
to
+38
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. 🌱 반영해도 좋고 넘어가도 좋아요. 🌱 위의 다른 코드들 처럼 ternary operator를 사용해보시는 것도 좋을 것 같습니다!
Suggested change
|
||||||||||||||
} | ||||||||||||||
return Math.log2(arr.length) | ||||||||||||||
} | ||||||||||||||
|
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.
🌱 반영해도 좋고 넘어가도 좋아요. 🌱
불필요한 tenary operator가 사용되어 가독성이 조금 떨어진다고 생각합니다! boolean 값을 직접 리턴 하시는 것보단 비교문 그 자체를 쓰시는 것이 좋을 것이라 생각됩니다!