-
Notifications
You must be signed in to change notification settings - Fork 2
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
[최현웅] 3주차 문제 해결 #13
base: main
Are you sure you want to change the base?
[최현웅] 3주차 문제 해결 #13
Conversation
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.
항상 깔끔하시군요. 일급객체, 순수함수, 커링 등 함수형 프로그래밍에 대해 공부해보셔도 좋을 것 같네요!
모던 ~~ 책들에 들어있을 것 같네요.
const getUniquePositions = (arr) => { | ||
return [...new Set(arr.join("|").split("|"))].map((v) => | ||
v.split(",").map((v) => Number(v)) | ||
); | ||
}; |
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.
set 없이 중복제거 해보시는건 어떤가요!
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.
생각해보니 map
메서드를 활용하면 Set을 사용하지 않고도 충분히 중복제거를 할 수 있겠네요. map으로도 구현해보고 둘의 차이를 정리해 봐야겠습니다!
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.
너무 고생하셨습니다 👍
process.exit(); | ||
}); | ||
|
||
const VIRUS = 2; |
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.
이렇게 매직넘버를 처리할 수 있었네요... 배워갑니다..👍
const targetPositions = graph.reduce((accVirus, row, i) => { | ||
const virusInRow = row | ||
.map((cell, j) => cell === target && [i, j]) | ||
.filter((value) => !!value); |
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.
자바스크립트에서는 이런식으로 stream처럼 사용하면 안느린가요??
자바 코테에서는 이렇게 사용하면 느려서 시간초과가 되는 경우가 꽤 있어서 궁금했습니다.
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.
아직 속도에 대한 고민은 해보지 않았지만, 지연평가를 사용해서 속도를 충분히 개선시킬 수 있다고 합니다. 아직, 지연평가에 대해선 공부해보지는 않았는데 메서드 체이닝으로 인해서 시간초과가 발생 한다면 지연 평가를 적용해볼까 합니다 :)
최근 함수형 프로그래밍 학습에 대한 필요성을 느껴서 조금씩 공부해보고 있는 중입니다! 선언적으로 UI를 다루는 리액트를 계속해서 사용하다보니 함수형 프로그래밍에 대해서 더 잘 알면 리액트를 더 잘 쓸 수 있을 것 같더라구요! |
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.
js로 하시니 많이 배워갑니다! 블로그 글도 새롭게 알게되어 도움이 많이 되었습니다 감사합니다!
} | ||
}; | ||
|
||
const checkDestructibleBlocks = (positions, board, targetPosition) => { |
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.
같은 블록인지 확인하고 배열에 추가하는 코드를 함수로 빼고 배열 메소드를 사용하니 깔끔하고 잘 읽히는 것 같습니다! positions.push(...destoryedPositions) 이렇게 배열에 추가하는 방법도 배워갑니다!
🖊️ 해결과정 기록
1️⃣ [1차]프렌즈 4블록 (1h)
💭 어떻게 접근했나요?
-
로 변경해 파괴되었음을 표시한다.2️⃣ 연구소(1h 30m)
💭 어떻게 접근했나요?
💪🏻 무엇을 얻었나요?
자바스크립트의 배열은 객체다.
문제를 해결할 때 중복 제거가 필요해서
Set
를 활용했는데, 자바스크립트에서 배열은 객체이고 객체를 비교할 때는 메모리 주소로 비교하므로 의도대로 중복제거가 되지 않았다. 객체를 비교할 때는 메모리 주소로 비교한다는 것을 알고 있었지만 막상 적용할 때는 떠오르지가 않아서 실수를 했다. 문제를 해결한 후, 자바스크립트Set
에 대해서 다시 알아보는 시간을 가졌다.(링크)자바스크립트 2차원 배열 복사하기
자바스크립트는 spread 연산자를 사용해서 배열을 복사할 수 있다.
하지만 2차원 배열 같은 경우는 제대로 복사되지 않는다. 따라서
map
을 활용해서 각 행에 있는 1차원 배열들을 따로 복사해줘야 한다.(링크)🎸 기타 추가사항