Merged
Conversation
oh-chaeyeon
approved these changes
Jan 6, 2025
Collaborator
There was a problem hiding this comment.
현재 코드에서 for을 사용해도 작동은 하지만, 반복문은 모든 수를 하나씩 순회해야 하기 때문에, 이 문제에서도 불필요하다는 생각이 듭니다. 그런 면에서, slice메서드가 배열의 특정 기간을 쉽게 추출하는 기능을 제공해서 반복문 대신 return numbers.slice(num1, num2 + 1); 하시는것을 추천드립니다:)
Comment on lines
+5
to
+8
| for (let i = 0; i < numbers.length - 1; i++) { | ||
| answer[i + 1] = numbers[i]; | ||
| } | ||
| answer[0] = numbers[numbers.length - 1]; |
Collaborator
There was a problem hiding this comment.
현재 for을 사용하여 각 숫자를 이동시키는 것도 좋지만, 혹시 메서드를 사용하면 코드가 단순해져서 이런 방법도 추천드립니다.
- numbers.pop()으로 배열의 마지막 요소를 제거하고,
- numbers.unshift()로 제거한 요소를 배열의 맨 앞에 추가.
const last = numbers.pop();
numbers.unshift(last);
Comment on lines
+2
to
+8
| const answer = []; | ||
| const minNum = Math.min(...arr); | ||
|
|
||
| for (const e of arr) { | ||
| if (e === minNum) continue; | ||
| answer.push(e); | ||
| } |
Collaborator
There was a problem hiding this comment.
새로운 배열 answer를 생성하고, for문을 이용해서 조건을 체크하고 숫자들을 추가하고 있지만, 이 부분에서 새로운 배열을 생성하면서 조건도 체크해주는 filter 메서드도 한번 사용해보시는 것도 좋을것 같습니다:)
Collaborator
There was a problem hiding this comment.
저는 많이 헤맨 문제였는데...Array.from을 사용한 배열 초기화한 부분과 reduce활용으로 깔끔하게 잘 구현된 코드인것 같습니다👍👍
bona1122
pushed a commit
to bona1122/AlgorithmStudy
that referenced
this pull request
Jan 9, 2025
* 배열 자르기, 기초 * 배열 회전시키기, 기초 * 제일 작은 수 제거하기, 중급 * 나누어 떨어지는 숫자 배열, 중급 * 행렬의 곱셈, 심화
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.
[배열]
📌 푼 문제
📝 간단한 풀이 과정
배열 자르기
배열 회전시키기
제일 작은 수 제거하기
Math.min()메서드를 이용해 현재 배열의 가장 작은 원소를 찾았습니다.나누어 떨어지는 숫자 배열
행렬의 곱셈