๐ŸŒ  ๋ฌธ์ œ

์ •์ˆ˜ n์ด ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์งˆ ๋•Œ, n ์ดํ•˜์˜ ํ™€์ˆ˜๊ฐ€ ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ๋‹ด๊ธด ๋ฐฐ์—ด์„ returnํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”.

๐ŸŒ  ์ œํ•œ์‚ฌํ•ญ

  • 1 ≤ n ≤ 100

๐ŸŒ  ์ž…์ถœ๋ ฅ ์˜ˆ

10 [1, 3, 5, 7, 9]
15 1, 3, 5, 7, 9, 11, 13, 15

๐ŸŒ  ์ž…์ถœ๋ ฅ ์˜ˆ ์„ค๋ช…

์ž…์ถœ๋ ฅ #1

  • 10 ์ดํ•˜์˜ ํ™€์ˆ˜๊ฐ€ ๋‹ด๊ธด ๋ฐฐ์—ด [1, 3, 5, 7, 9]๋ฅผ returnํ•ฉ๋‹ˆ๋‹ค.

์ž…์ถœ๋ ฅ #1

  • 15 ์ดํ•˜์˜ ํ™€์ˆ˜๊ฐ€ ๋‹ด๊ธด ๋ฐฐ์—ด [1, 3, 5, 7, 9, 11, 13, 15]๋ฅผ returnํ•ฉ๋‹ˆ๋‹ค.

๐Ÿงž ํ’€์ด

function solution(n) {
    let answer = []
    for (let i = 1; i <= n; i += 2)
      { answer.push(i) }
    return answer;
}

+ Recent posts