두개 뽑아서 더하기
풀이 1
function solution(numbers) {
let set = new Set()
for(let i = 0; i< numbers.length; i++) {
for(let j = 0; j< i; j++) {
let plus = numbers[i] + numbers[j];
set.add(plus);
}
}
let newNum = Array.from(set);
newNum.sort((a,b)=> a-b);
return newNum
}
풀이 2
function solution(numbers) {
let array = []
for(let i = 0; i< numbers.length; i++) {
for(let j = 0; j< i; j++) {
let plus = numbers[i] + numbers[j];
if(array.includes(plus)) continue; else array.push(plus)
}
}
array.sort((a,b)=> a-b);
return console.log(array)
}
solution([5,0,2,7])