๋ฐ์ํ
๐ค๋ฌธ์ ํด๊ฒฐ
1. 2์ค ํฌ๋ฌธ์ ์ด์ฉํ์ฌ ์๋ก ๋ค๋ฅธ 2 ์ซ์๋ฅผ ๋ํ ๊ฐ์ ๋ฐฐ์ด์ ๋ด๋๋ค.
2. ์ค๋ณต์ ์ ๊ฑฐํ๋ค set
3. ์ ๋ ฌํ๋ค.
๐จ
๐ป์์ค ์ฝ๋
function solution(numbers) {
var answer = [];
for ( var i = 0; i < numbers.length; i++) {
for ( var j = 0; j < numbers.length; j++) {
if ( i != j) {
answer.push(numbers[i]+numbers[j])
}
}
}
const result = [ ...new Set(answer)]
result.sort((a,b)=>{
return a-b
})
return result;
}
๐๋ฌธ์ ํ์ธ
์ถ์ฒ: ํ๋ก๊ทธ๋๋จธ์ค
๋งํฌ: https://programmers.co.kr/learn/courses/30/lessons/68644?language=javascript
๋ฐ์ํ
'Algorithm Problem > JavaScript' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[javascript] ํ๋ก๊ทธ๋๋จธ์ค - ๋คํธ์ํฌ (0) | 2020.10.21 |
---|---|
[javascript] ํ๋ก๊ทธ๋๋จธ์ค - ๋จ์ด ๋ณํ (0) | 2020.10.20 |
[JavaScript] ํ๋ก๊ทธ๋๋จธ์ค - ๋ฒ ์คํธ์จ๋ฒ (0) | 2020.08.01 |
[JavaScript] ํ๋ก๊ทธ๋๋จธ์ค - ํ๋ฆฐํฐ (0) | 2020.07.28 |
[JavaScript] ํ๋ก๊ทธ๋๋จธ์ค - ์์ด ๋๋ง์๊ธฐ(Summer/Winter Coding(~2018)) (0) | 2020.07.26 |