Merged
Conversation
oh-chaeyeon
approved these changes
Jan 6, 2025
Collaborator
oh-chaeyeon
left a comment
There was a problem hiding this comment.
수고많으셨습니다!!😊 코드리뷰하면서 많이 배우고 갑니다~
| if (arr.length <= 1) return [-1]; | ||
| const min = Math.min(...arr); | ||
| const minIdx = arr.indexOf(min); | ||
| arr.splice(minIdx, 1); // splice는 제거된 요소들의 배열을 반환하므로 return arr.splice(minIdx, 1);는 틀리게된다. |
Collaborator
There was a problem hiding this comment.
저는 filter를 사용해서 문제를 풀었는데, splice를 이용해서 푸는 방법도 알아갑니다!! arr이 [4, 3, 2, 1]일때, arr.splice(minIdx, 1);는 1일텐데, return arr.splice(minIdx, 1);를 하면 1를 제거한 배열이 아닌 1를 반환해서 틀리는군요....잘 알아둬야겠군요!!
Comment on lines
+2
to
+5
| const add = (a, b) => a + b; | ||
| const addArrays = (a, b) => a.map((item, idx) => add(item, b[idx])); | ||
|
|
||
| return arr1.map((row, i) => addArrays(row, arr2[i])); |
Collaborator
There was a problem hiding this comment.
add함수랑 addArrays함수를 만들어서 문제를 푼 부분에서 이런 방식으로 푸니깐 더 코드가 깔끔해보이네요👍👍 배우고 갑니다~
|
|
||
| // 행렬 요소 하나씩 값 만들기 | ||
| return result.map((row, i) => | ||
| r.map((item, j) => { |
Collaborator
There was a problem hiding this comment.
r.map -> row.map 으로 변경해야 할것 같습니다:)
Comment on lines
+23
to
+31
| const coords = Array.from(points).map((p) => p.split(",").map(Number)); | ||
| const [minX, maxX] = [ | ||
| Math.min(...coords.map((p) => p[0])), | ||
| Math.max(...coords.map((p) => p[0])), | ||
| ]; | ||
| const [minY, maxY] = [ | ||
| Math.min(...coords.map((p) => p[1])), | ||
| Math.max(...coords.map((p) => p[1])), | ||
| ]; |
Collaborator
There was a problem hiding this comment.
그리고 map과 Math.min(), Math.max()가 각각 두 번 호출하기에, 각 좌표 배열을 두 번 순회해야 하는 부분을 reduce메서드 사용하면 한번의 순회로 모든 값을 처리할수 있어서 이런식으로 개선해보는것이 어떨까 생각해봤습니다!
const coords = Array.from(points).map((p) => p.split(",").map(Number));
const [minX, maxX, minY, maxY] = coords.reduce(
([minX, maxX, minY, maxY], [x, y]) => [
Math.min(minX, x),
Math.max(maxX, x),
Math.min(minY, y),
Math.max(maxY, y),
],
[Infinity, -Infinity, Infinity, -Infinity]
);
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
[배열]
배열 메서드들을 사용하며 리마인드 했던 내용들과 문제를 풀며 배열 문제에서 얻은 인사이트를 정리했습니다.
📌 푼 문제
📝 간단한 풀이 과정
제일 작은 수 제거하기
행렬의 덧셈
행렬의 곱셈
교점에 별 만들기
n^2 배열 자르기
아래의 핵심사항을 파악하는 것이 어려웠습니다.