문제 출처
프로그래머스 lev1 - 두 개 뽑아서 더하기
문제

나의 풀이
function solution(numbers) {
let tmp = Array.from({length:2}, () => 0);
let ch = Array.from({length:numbers.length}, () => 0);
let answer = [];
function Sum (L) {
if (L==2) {
let sum=tmp.reduce((a,b)=>a+b,0);
if (!answer.includes(sum)) {
answer.push(sum);
}
}
else {
for (let i=0; i<numbers.length; i++) {
if (ch[i]==0) {
tmp[L]=numbers[i];
ch[i]=1;
Sum(L+1);
ch[i]=0;
}
}
}
}
Sum(0)
answer.sort((a,b)=>a-b);
return answer;
}
console.log(solution([2, 1, 3, 4, 1]));