-
Notifications
You must be signed in to change notification settings - Fork 4
[unn04012] 25.01.02 #10
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
oh-chaeyeon
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.
수고하셨습니다!!😊
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.
현재 코드에서 for을 사용해도 작동은 하지만, 반복문은 모든 수를 하나씩 순회해야 하기 때문에, 이 문제에서도 불필요하다는 생각이 듭니다. 그런 면에서, slice메서드가 배열의 특정 기간을 쉽게 추출하는 기능을 제공해서 반복문 대신 return numbers.slice(num1, num2 + 1); 하시는것을 추천드립니다:)
| for (let i = 0; i < numbers.length - 1; i++) { | ||
| answer[i + 1] = numbers[i]; | ||
| } | ||
| answer[0] = numbers[numbers.length - 1]; |
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.
현재 for을 사용하여 각 숫자를 이동시키는 것도 좋지만, 혹시 메서드를 사용하면 코드가 단순해져서 이런 방법도 추천드립니다.
- numbers.pop()으로 배열의 마지막 요소를 제거하고,
- numbers.unshift()로 제거한 요소를 배열의 맨 앞에 추가.
const last = numbers.pop();
numbers.unshift(last);
| const answer = []; | ||
| const minNum = Math.min(...arr); | ||
|
|
||
| for (const e of arr) { | ||
| if (e === minNum) continue; | ||
| answer.push(e); | ||
| } |
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.
새로운 배열 answer를 생성하고, for문을 이용해서 조건을 체크하고 숫자들을 추가하고 있지만, 이 부분에서 새로운 배열을 생성하면서 조건도 체크해주는 filter 메서드도 한번 사용해보시는 것도 좋을것 같습니다:)
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.
저는 많이 헤맨 문제였는데...Array.from을 사용한 배열 초기화한 부분과 reduce활용으로 깔끔하게 잘 구현된 코드인것 같습니다👍👍
* 배열 자르기, 기초 * 배열 회전시키기, 기초 * 제일 작은 수 제거하기, 중급 * 나누어 떨어지는 숫자 배열, 중급 * 행렬의 곱셈, 심화
[배열]
📌 푼 문제
📝 간단한 풀이 과정
배열 자르기
배열 회전시키기
제일 작은 수 제거하기
Math.min()메서드를 이용해 현재 배열의 가장 작은 원소를 찾았습니다.나누어 떨어지는 숫자 배열
행렬의 곱셈