๐Ÿค ์€์ง€log ๐Ÿค

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค:Javascript] 5๋ช…์”ฉ ๋ณธ๋ฌธ

๐ŸŒˆ ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค:Javascript] 5๋ช…์”ฉ

Eun_zii 2024. 3. 12. 17:47

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค Lv.0

- 5๋ช…์”ฉ

 

๐Ÿ’š ๋ฌธ์ œ์„ค๋ช…

  • ์ตœ๋Œ€ 5๋ช…์”ฉ ํƒ‘์Šน๊ฐ€๋Šฅํ•œ ๋†€์ด๊ธฐ๊ตฌ๋ฅผ ํƒ€๊ธฐ ์œ„ํ•ด ์ค„์„ ์„œ์žˆ๋Š” ์‚ฌ๋žŒ๋“ค์˜ ์ด๋ฆ„์ด ๋‹ด๊ธด ๋ฌธ์ž์—ด ๋ฆฌ์ŠคํŠธ names๊ฐ€ ์ฃผ์–ด์งˆ ๋•Œ, ์•ž์—์„œ ๋ถ€ํ„ฐ 5๋ช…์”ฉ ๋ฌถ์€ ๊ทธ๋ฃน์˜ ๊ฐ€์žฅ ์•ž์— ์„œ์žˆ๋Š” ์‚ฌ๋žŒ๋“ค์˜ ์ด๋ฆ„์„ ๋‹ด์€ ๋ฆฌ์ŠคํŠธ๋ฅผ returnํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”. ๋งˆ์ง€๋ง‰ ๊ทธ๋ฃน์ด 5๋ช…์ด ๋˜์ง€ ์•Š๋”๋ผ๋„ ๊ฐ€์žฅ ์•ž์— ์žˆ๋Š” ์‚ฌ๋žŒ์˜ ์ด๋ฆ„์„ ํฌํ•จํ•ฉ๋‹ˆ๋‹ค.

 

๐Ÿ’š ์ œํ•œ์กฐ๊ฑด

  • 5 ≤ names์˜ ๊ธธ์ด ≤ 30
  • 1 ≤ names์˜ ์›์†Œ์˜ ๊ธธ์ด ≤ 10
  • names์˜ ์›์†Œ๋Š” ์˜์–ด ์•ŒํŒŒ๋ฒณ ์†Œ๋ฌธ์ž๋กœ๋งŒ ์ด๋ฃจ์–ด์ ธ ์žˆ์Šต๋‹ˆ๋‹ค.

 

๐Ÿ’š ํ’€์ด

function solution(names) {
    const answer = [];
    for ( let i = 0; i < names.length; i+= 5) {
        answer.push(names[i])
    } 
    return answer
}

 

โœ… 

n๊ฐœ ๊ฐ„๊ฒฉ์˜ ์›์†Œ๋“ค ๋ฌธ์ œํ’€๋•Œ ์ฒ˜๋Ÿผ 

names ๋ฐฐ์—ด์˜ ์š”์†Œ i๋ฅผ 5๋งŒํผ ์ฆ๊ฐ€์‹œํ‚ค๋ฉด์„œ ๋ฐ˜๋ณตํ•˜์—ฌ์ฃผ๊ณ ,

names[i]์˜ ๊ฐ’์„ push( ) ๋ฉ”์„œ๋“œ๋กœ ๋นˆ๋ฐฐ์—ด answer์— ์ถ”๊ฐ€ํ•ด์ค€ํ›„ answer๋ฅผ return ํ•ด์ค€๋‹ค.

728x90