Skip to content

[정렬] 예제 및 실전문제 해결 (이윤성) #12

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

2yunseong
Copy link
Contributor

코멘트로 설명 남기겠습니다.


// 필요한 함수 선언

inputNumbers.sort((a, b) => b - a); // 내림차순 정렬 API
Copy link
Contributor Author

Choose a reason for hiding this comment

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

sort는 자바스크립트 배열의 내장 API로, 인자로 정렬기준을 알려주는 callback을 전달해줍니다.


students.sort((a, b) => a.grade - b.grade);

const result = students.map((student) => student.name).join(' ');
Copy link
Contributor Author

Choose a reason for hiding this comment

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

students 배열 객체에서 이름을 뽑아 결과 문자열을 만들어 주는 로직입니다.
배열 API를 적절하게 사용하면 로직을 간단하게 줄일 수 있습니다.
python 같은 경우도 map, 등의 리스트 API를 제공하니 잘 공부해보시기 바랍니다!
(자바는 아쉽게도 쓸려면 stream으로 변환한 후에 사용해야 될 것 같습니다! 따로 공부해보시기 바랍니다.)

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.

1 participant