Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[๐Ÿ”ง Front-End Error] #4 / Reduce of empty array / 2021-09-27 #232

Open
youngseo-kangg opened this issue Sep 27, 2021 · 0 comments
Open
Assignees
Labels
Error Error Front-End Front-End Tasks
Milestone

Comments

@youngseo-kangg
Copy link
Collaborator

์–ด๋–ค ์—๋Ÿฌ์ธ๊ฐ€์š”?

  • ์Šคํ† ์–ด์—์„œ ๋ณด๊ด€ํ•˜๊ณ  ์žˆ๋Š” ๊ฐ’์„ ๊ฐ€์ ธ์™€ map, reduceํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ฐ์ดํ„ฐ๋ฅผ ๋ณด๊ธฐ ํŽธํ•˜๋„๋ก ๊ฐ€๊ณตํ•˜๊ณ  ์žˆ์—ˆ์Œ
  • reduce๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ถ€๋ถ„์—์„œ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•จ

์—๋Ÿฌ ๋ฉ”์‹œ์ง€

  • TypeError : Reduce of empty array with no initial value

์—๋Ÿฌ ํ•ธ๋“ค๋ง ๋ฐฉ๋ฒ•

  • reduce๋Š” ์ด 4๊ฐœ์˜ ์ธ์ž (๋ˆ„์ ๋˜๋Š” ๊ฐ’ acc, ํ˜„์žฌ ๊ฐ’ cur, ํ˜„์žฌ ์ธ๋ฑ์Šค idx, ์›๋ณธ ๋ฐฐ์—ด src)๋ฅผ ๊ฐ€์ง€๊ณ  ํ•„์š”์— ๋”ฐ๋ผ ์ดˆ๊ธฐ๊ฐ’์„ ์‚ฌ์šฉํ•จ. ๋งŒ์•ฝ ์ดˆ๊ธฐ๊ฐ’์„ ์„ค์ •ํ•˜์ง€ ์•Š๋Š”๋‹ค๋ฉด ์›๋ณธ ๋ฐฐ์—ด์˜ ์ฒซ๋ฒˆ์งธ ๊ฐ’์„ ์ดˆ๊ธฐ๊ฐ’์œผ๋กœ ์„ค์ •ํ•˜๊ณ  ์‚ฌ์šฉํ•˜๊ฒŒ ๋จ.
  • ๋ฐฐ์—ด์— ๊ฐ’์ด ์žˆ๋Š” ๊ฒฝ์šฐ์—๋Š” ์ดˆ๊ธฐ๊ฐ’์„ ์„ค์ •ํ•˜์ง€ ์•Š์•„๋„ ์ •์ƒ์ ์œผ๋กœ ์ž‘๋™ํ•˜๋‚˜, filter๋‚˜ map์„ ๊ฑฐ์ณ ๋งŒ์•ฝ ๋ฐฐ์—ด์— ์•„๋ฌด ๊ฐ’๋„ ๋‚จ์•„์žˆ์ง€ ์•Š์€ ์ƒํƒœ์—์„œ reduce๋ฅผ ์‚ฌ์šฉํ•˜๊ฒŒ ๋˜๋ฉด ๋‚˜์˜ค๋Š” ์—๋Ÿฌ์˜€์Œ
  • ๊ทธ๋ž˜์„œ reduceํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ ์ดˆ๊ธฐ๊ฐ’์œผ๋กœ 0์„ ์„ค์ •ํ•ด์ฃผ๋‹ˆ ํ•ด๊ฒฐ๋˜์—ˆ์Œ.
    • array.reduce((acc,cur)=> { return .... }, 0)

์—๋Ÿฌ ํ•ธ๋“ค๋ง์„ ์œ„ํ•ด ์ฐธ๊ณ ํ•œ ๋ ˆํผ๋Ÿฐ์Šค ๋งํฌ

TypeError: Reduce of empty array with no initial value

@youngseo-kangg youngseo-kangg added Front-End Front-End Tasks Error Error labels Sep 27, 2021
@youngseo-kangg youngseo-kangg changed the title [๐Ÿ”ง Front-End Error] #5 / Reduce of empty array / 2021-09-27 [๐Ÿ”ง Front-End Error] #4 / Reduce of empty array / 2021-09-27 Sep 27, 2021
@youngseo-kangg youngseo-kangg added this to the Advanced milestone Sep 27, 2021
@youngseo-kangg youngseo-kangg added the C:0.5h completed under 30 minutes label Sep 27, 2021
@minjman2659 minjman2659 removed the C:0.5h completed under 30 minutes label Oct 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Error Error Front-End Front-End Tasks
Projects
None yet
Development

No branches or pull requests

3 participants