const solution = (...dwarves) => {
const sum = dwarves.reduce((a, b) => a + b);
for (let i = 0; i < dwarves.length - 1; i++) {
const former = dwarves[i];
for (let j = 1; j < dwarves.length; j++) {
const latter = dwarves[j];
if (sum - (former + latter) == 100) {
return dwarves.filter((v, index) => index !== i && index !== j);
}
}
}
};
const result = solution(20, 7, 23, 19, 10, 15, 25, 8, 13);
console.log(result);
function solution(arr) {
let answer = arr;
let sum = answer.reduce((a, b) => a + b, 0);
for (let i = 0; i < 8; i++) {
for (let j = i + 1; j < 9; j++) {
if (sum - (answer[i] + answer[j]) == 100) {
answer.splice(j, 1);
answer.splice(i, 1);
}
}
}
return answer;
}
let arr = [20, 7, 23, 19, 10, 15, 25, 8, 13];
console.log(solution(arr));