-
-
Notifications
You must be signed in to change notification settings - Fork 305
[FEhyoeun] WEEK 02 solutions #2036
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
Conversation
Seoya0512
left a comment
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.
안녕하세요, 문제 푸시느라 고생 많으셨습니다😊
저도 타입스크립트로 개발해오던 사람이라 반가운 마음을 가지며 코드 리뷰 진행했습니다.
그럼 다음 주도 화이팅하세요!!
| let sObj = {} | ||
| let tObj = {} | ||
|
|
||
| s.split('').sort().map((sChar) => { |
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.
sort()메소드를 사용하면 시간 복잡도가 O(n log n)가 된다고 알고 있습니다.
작성해주신 전체 코드에서 마지막 반환값 순서를 보장하기 위해 sort처리를 하신 것 같은데 다른 방법으로 시간복잡도를 개선할 수 있을 것 같아요!
| } | ||
| }) | ||
|
|
||
| return JSON.stringify(sObj) === JSON.stringify(tObj) |
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.
반환할때 JSON.stringify() 는 객체 비교를 위해 사용하고 계신 것 같아요.
해당 부부은 비싼 연산이기 때문에 for-loop를 통해서 key,value를 검증하는 것이 더 낫지 않을까? 라는 생각이 드네요 🤔
// 예시
for (let key in sObj) {
if (sObj[key] !== tObj[key]) return false
}그리고 객체 2개가 아닌 1개를 사용해서 해당 문제를 푸는 방법도 있을 것 같아요 : )
답안 제출 문제
작성자 체크 리스트
In Review로 설정해주세요.검토자 체크 리스트
Important
본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!