Skip to content

Comments

[moonjonghoo]25.01.02#2

Merged
JooKangsan merged 10 commits intomainfrom
jh
Jan 9, 2025
Merged

[moonjonghoo]25.01.02#2
JooKangsan merged 10 commits intomainfrom
jh

Conversation

@Moonjonghoo
Copy link
Collaborator

배열

배열에 해당하는 알고리즘은 사실 그렇게 많지않고 배열에서 메서드들에대해서 학습했습니다.

  1. slice
    slice 는 주로 배열내부에서 특정부분을 잘라서 리턴할때 사용합니다.
    이때 원본배열은 수정되지않기때문에 원본배열 자체를 수정하고싶을떄 splice 를 사용하면됩니다.
  2. sort
    배열을 정렬할때 사용하는 메서드입니다.
    배열의 기준은 compareFunction 에의해셔 결정되며 만약 작성하지않으면 유니코드순으로 자동정렬됩니다.
let arr=[1,3,2,5,8]

arr,.sort(function(a,b){
return a-b
}
)

📌 푼 문제

기초

문제이름 문제링크 solve
배열 자르기 https://school.programmers.co.kr/learn/courses/30/lessons/120833 완료
배열 원소의 길이 https://school.programmers.co.kr/learn/courses/30/lessons/120854 완료
배열 회전시키기 https://school.programmers.co.kr/learn/courses/30/lessons/120844 완료
중복된 숫자 개수 https://school.programmers.co.kr/learn/courses/30/lessons/120583 완료

중급

문제이름 문제링크 solve
제일 작은 수 제거하기 https://school.programmers.co.kr/learn/courses/30/lessons/12935 완료
행렬의 덧셈 https://school.programmers.co.kr/learn/courses/30/lessons/12950 완료
나누어 떨어지는 숫자 배열 https://school.programmers.co.kr/learn/courses/30/lessons/12910 완료

심화

문제이름 문제링크 solve
행렬의 곱셈 https://school.programmers.co.kr/learn/courses/30/lessons/12949 완료

Copy link
Collaborator

@JustDevRae JustDevRae left a comment

Choose a reason for hiding this comment

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

수고 많으셨습니다!

Comment on lines +7 to +11
for (let i = 0; i < arr.length; i++) {
if (arr[i] !== min) {
answer.push(arr[i]);
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

for문 부분을 filter 메서드를 사용하면 더 간결하게 작성할 수 있을 것 같아요!

Comment on lines +3 to +5
for (let i = 0; i < strlist.length; i++) {
answer.push(strlist[i].length);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

map 메서드를 사용하면 더 간결하게 구현하실 수 있으실 것 같아요!

Comment on lines +12 to +14
answer.sort(function (a, b) {
return a - b;
});
Copy link
Collaborator

@JustDevRae JustDevRae Jan 6, 2025

Choose a reason for hiding this comment

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

sort를 화살표 함수가 아닌 익명 함수로 표현하신 이유가 있나요? 단순히 궁금해서 질문드려요!

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 +18
for (let i = 0; i < numbers.length; i++) {
if (direction === "right") {
let start = numbers[numbers.length - 1];
answer = numbers.slice(0, numbers.length - 1);
answer.unshift(start);
}
if (direction === "left") {
let start = numbers[0];
answer = numbers.slice(1, numbers.length);
answer.push(start);
}
}

return answer;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

조건문으로도 잘 동작하는것 같은데 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.

그러네요 수정하겠습니다!

@JooKangsan JooKangsan merged commit 02d9142 into main Jan 9, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants