Skip to content
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

level01.비밀지도 #505

Merged
merged 2 commits into from
Oct 8, 2022
Merged

level01.비밀지도 #505

merged 2 commits into from
Oct 8, 2022

Conversation

JiaLee0707
Copy link
Collaborator

📅 문제를 푼 날짜

  • 2022.09.11

🔗 문제 링크

💬 의견

@@ -0,0 +1,18 @@
function solution(n, arr1, arr2) {
Copy link
Member

Choose a reason for hiding this comment

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

폴더명 변경이 필요할 것 같아요~! level01.[1차]_비밀지도 라는 폴더가 있네요!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

그렇네요! 변경했습니당 :)

Comment on lines 4 to 5
arr1 = arr1.map((value) => value.toString(2));
arr2 = arr2.map((value) => value.toString(2));
Copy link
Member

Choose a reason for hiding this comment

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

여기에서 arr1/arr2의 길이만큼 각각 반복문을 돌고 7번째 줄에서 다시 돌고 있어요.
한 번에 할 수 있는 방법이 없을까요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

arr1과 arr2의 길이가 변수 n으로 주어지니까 for문으로 한 번에 해도 될 것 같아요!
그러면 바로 아래에 있는 for문에서 const value1 = arr1[i].toString(2).padStart(n, '0'); 이렇게 한 번에 하면
더 줄어들겠네요!!

Copy link
Member

Choose a reason for hiding this comment

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

const line = (arr1[i] | arr2[i]).toString(2);
const replace_format = line.replace(/1/g, '#').replace(/0/g, ' ');

참고로 .toString을 활용해 두 가지 숫자가 OR 연산된 결과값을 바로 받을 수 있답니다!
자세한 부분은 제 PR을 확인해보세요!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

오! 비트 연산자!!! 생각하지 못한 방법이네요!!
감사합니다 :)

Comment on lines 13 to 14
if(value1[j] === '1' || value2[j] === '1') answer[i] += '#';
else answer[i] += ' ';
Copy link
Member

@areumsheep areumsheep Sep 29, 2022

Choose a reason for hiding this comment

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

replace가 O(n)이라는 이야기가 있어서 체이닝을 할 경우엔 O(n)을 2번 하는거라 for문이 더 낫지 않을까? 생각이 들어 테스트해보았는데 for문이 더 느리네요... 어떤 차이가 있는지 궁금해져요 +_+

테스트한 결과 자세히 보기

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

어떤 함수였는지는 기억이 안나지만
내장 함수를 사용하는 것보다 for문이 더 빠른 경우가 있었는데
replace는 for문보다 빠르다니 놀라워요 !!

궁금증을 테스트해주셔서 감사합니다 :)

Copy link
Member

Choose a reason for hiding this comment

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

정정: 환경에 따라 상이하기 때문에 이번에는 replace를 사용하는 것이 더 좋아보이네요!

@JiaLee0707 JiaLee0707 merged commit 37d1e33 into master Oct 8, 2022
@JiaLee0707 JiaLee0707 deleted the JiaLee0707-patch-7 branch October 8, 2022 08:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants