문제
일과를 마치고 돌아온 난쟁이가 일곱이 아닌 아홉 명이다.
일곱 난쟁이의 키가 주어질 때 백설공주와 함께 지내던 일곱 난쟁이를 출력
풀이 과정
const solutionA = (numArray) => {
const excludes = [];
const total = numArray.reduce((acc, cur) => acc + cur, 0);
const sumheight = total - 100;
for (let i = 0; i < numArray.length - 1; i++) {
const iHeight = numArray[i];
for (let j = 1; j < numArray.length; j++) {
const jHeight = numArray[j];
if (iHeight + jHeight === sumheight) {
excludes.push(iHeight);
excludes.push(jHeight);
break;
}
}
if (excludes.length) break;
}
return numArray.filter((el) => !excludes.includes(el));
};
const testA = solutionA([20, 7, 23, 19, 10, 15, 25, 8, 13]);
console.log(testA);
틀린 부분이 있거나 보충해야 할 내용이 있다면 댓글이나 DM(sungstonemin)으로 알려주시면 감사하겠습니다😄