인프런 영문 브랜드 로고
인프런 영문 브랜드 로고

Inflearn Community Q&A

리쿤's profile image
리쿤

asked

Introduction to Javascript Algorithm Problem Solving (Coding Test Preparation)

4. Graduation gift

졸업선물 화살표함수 질문

Written on

·

159

0

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <script>
        function solution(m, product){
            let answer=0;
            n=product.length;
            product.sort((a, b)=>(a[0]+a[1])-(b[0]+b[1]));
            // console.log(product);
            for(let i=0; i<n; i++){
                let money=m
            }

 

            return answer;
        }
        let arr = [[6,6], [2,2], [4,3], [4,5], [10,3]];
        console.log(solution(28, arr));
    </script>
</body>
</html>
 
이 코드에서  product.sort((a, b)=>(a[0]+a[1])-(b[0]+b[1])); 가 잘 이해되지 않습니다. (a[0]+a[1])-(b[0]+b[1])빼주면 왜 sort함수에 의해 정렬이 되는지 궁금합니다.
javascript코테 준비 같이 해요!

Answer 1

1

codingcamp님의 프로필 이미지
codingcamp
Instructor

안녕하세요^^

이건 저도 내부에서 그렇게 규정되어 있나보다 하고 외우고 합니다. 

a-b는 오름차순, b-a는 내림차순입니다.

리쿤's profile image
리쿤

asked

Ask a question