const largestProductOfThree = function (arr) {
const sorted = arr.slice().sort((a, b) => a - b);
// 배열을 오름차순으로 정렬해 새로운 변수에 담아준다
const len = arr.length;
// 배열의 길이를 len 변수에 담아준다
const candi1 = sorted[len - 1] * sorted[len - 2] * sorted[len - 3];
// 배열의 길이는 최소 3개 이상이므로, 뒤에서부터 3개의 요소를 먼저 곱해준다 (가장 큰 세 개의 숫자를 곱함)
const candi2 = sorted[len - 1] * sorted[0] * sorted[1];
// 앞에서부터 2개와 마지막 요소를 곱해준다 (음수이면 두 개를 곱해서 양수로 만들어주려고)
return Math.max(candi1, candi2);
// 두 가지 후보 중 큰 쪽을 리턴한다.
};