๐ ํ๋ก๊ทธ๋๋จธ์ค
[ํ๋ก๊ทธ๋๋จธ์ค:Javascript] ๋ค์์ 5๋ฑ ์๋ก
Eun_zii
2024. 2. 28. 17:37
ํ๋ก๊ทธ๋๋จธ์ค Lv.0
- ๋ค์์ 5๋ฑ ์๋ก
๐ ๋ฌธ์ ์ค๋ช
- ์ ์๋ก ์ด๋ฃจ์ด์ง ๋ฆฌ์คํธ num_list๊ฐ ์ฃผ์ด์ง๋๋ค. num_list์์ ๊ฐ์ฅ ์์ 5๊ฐ์ ์๋ฅผ ์ ์ธํ ์๋ค์ ์ค๋ฆ์ฐจ์์ผ๋ก ๋ด์ ๋ฆฌ์คํธ๋ฅผ returnํ๋๋ก solution ํจ์๋ฅผ ์์ฑํด์ฃผ์ธ์.
๐ ์ ํ์กฐ๊ฑด
- 6 ≤ num_list์ ๊ธธ์ด ≤ 30
- 1 ≤ num_list์ ์์ ≤ 100
๐ ํ์ด
function solution(num_list) {
const answer = num_list.sort((a,b)=>a-b)
return answer.slice(5)
}
โ
์ฐ์ ์ค๋ฆ์ฐจ์์ผ๋ก num_list๋ฅผ ์ ๋ ฌํด์ค๊ฒ์ answer์ ๋ด์๋๊ณ ๊ฐ์ฅ์์ 5๊ฐ์ ์๋ฅผ ์ ์ธํ๊ณ returnํด์ผํ๊ธฐ๋๋ฌธ์
์ค๋ฆ์ฐจ์์ผ๋ก ์ ๋ ฌ๋ num_list๋ฅผ slice(5) ํด์ return ํด์ฃผ์๋ค.
728x90