๐Ÿ’ข[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ์ง์ˆ˜์˜ ํ•ฉ

Chobbyยท2022๋…„ 10์›” 1์ผ
2

Programmers

๋ชฉ๋ก ๋ณด๊ธฐ
54/349

๐Ÿงก๋ฌธ์ œ ์„ค๋ช…

์ •์ˆ˜ n์ด ์ฃผ์–ด์งˆ ๋•Œ, n์ดํ•˜์˜ ์ง์ˆ˜๋ฅผ ๋ชจ๋‘ ๋”ํ•œ ๊ฐ’์„ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”.


๐Ÿ’›์ œํ•œ์‚ฌํ•ญ

0 < n โ‰ค 1000


๐Ÿ’š์ž…์ถœ๋ ฅ ์˜ˆ

nresult
1030
46

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

์ž…์ถœ๋ ฅ ์˜ˆ #1

  • n์ด 10์ด๋ฏ€๋กœ 2 + 4 + 6 + 8 + 10 = 30์„ return ํ•ฉ๋‹ˆ๋‹ค.

์ž…์ถœ๋ ฅ ์˜ˆ #2

  • n์ด 4์ด๋ฏ€๋กœ 2 + 4 = 6์„ return ํ•ฉ๋‹ˆ๋‹ค.

๐Ÿ’œ๋‚˜์˜ ํ’€์ด

const solution = (n) => new Array(n).fill(0).map((_,i) => i+1).reduce((a,b) => b%2 === 0 ? a+b : a,0)
profile
๋‚ด ์ง€์‹์„ ๊ณต์œ ํ•  ์ˆ˜ ์žˆ๋Š” ๋Œ€๋‹ดํ•จ

0๊ฐœ์˜ ๋Œ“๊ธ€