From 457f85f01e160d7798a4162a0464946488452df7 Mon Sep 17 00:00:00 2001 From: nari Date: Wed, 8 Nov 2023 00:42:44 +0900 Subject: [PATCH 01/17] =?UTF-8?q?README=20:=20=ED=94=84=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EB=9E=A8=20=EC=86=8C=EA=B0=9C=20=EB=B0=8F=20=EA=B5=AC=ED=98=84?= =?UTF-8?q?=20=EA=B8=B0=EB=8A=A5=20=EB=AA=A9=EB=A1=9D,=20=EC=8B=A4?= =?UTF-8?q?=ED=96=89=20=EC=98=88=EC=8B=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 209 ++++-------------------------------------------------- 1 file changed, 15 insertions(+), 194 deletions(-) diff --git a/README.md b/README.md index aff2c46597..fd9176f68e 100644 --- a/README.md +++ b/README.md @@ -1,129 +1,27 @@ # ๋ฏธ์…˜ - ๋กœ๋˜ -## ๐Ÿ” ์ง„ํ–‰ ๋ฐฉ์‹ +## ํ”„๋กœ๊ทธ๋žจ ์†Œ๊ฐœ -- ๋ฏธ์…˜์€ **๊ธฐ๋Šฅ ์š”๊ตฌ ์‚ฌํ•ญ, ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์š”๊ตฌ ์‚ฌํ•ญ, ๊ณผ์ œ ์ง„ํ–‰ ์š”๊ตฌ ์‚ฌํ•ญ** ์„ธ ๊ฐ€์ง€๋กœ ๊ตฌ์„ฑ๋˜์–ด ์žˆ๋‹ค. -- ์„ธ ๊ฐœ์˜ ์š”๊ตฌ ์‚ฌํ•ญ์„ ๋งŒ์กฑํ•˜๊ธฐ ์œ„ํ•ด ๋…ธ๋ ฅํ•œ๋‹ค. ํŠนํžˆ ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ•˜๊ธฐ ์ „์— ๊ธฐ๋Šฅ ๋ชฉ๋ก์„ ๋งŒ๋“ค๊ณ , ๊ธฐ๋Šฅ ๋‹จ์œ„๋กœ ์ปค๋ฐ‹ ํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ์ง„ํ–‰ํ•œ๋‹ค. -- ๊ธฐ๋Šฅ ์š”๊ตฌ ์‚ฌํ•ญ์— ๊ธฐ์žฌ๋˜์ง€ ์•Š์€ ๋‚ด์šฉ์€ ์Šค์Šค๋กœ ํŒ๋‹จํ•˜์—ฌ ๊ตฌํ˜„ํ•œ๋‹ค. +- ๋กœ๋˜๋Š” ํ•œ ์žฅ์— 1000์›์œผ๋กœ, ์›ํ•˜๋Š” ๋งŒํผ ๊ตฌ๋งค ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. +- ๊ตฌ๋งคํ•œ ๋กœ๋˜์— ๋Œ€ํ•œ ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•˜๋ฉด, ๋‹น์ฒจ ๋‚ด์—ญ ๋ฐ ์ˆ˜์ต๋ฅ ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋Š” ํ”„๋กœ๊ทธ๋žจ์ž…๋‹ˆ๋‹ค. -## ๐Ÿ“ฎ ๋ฏธ์…˜ ์ œ์ถœ ๋ฐฉ๋ฒ• +## ๊ธฐ๋Šฅ ๋ชฉ๋ก -- ๋ฏธ์…˜ ๊ตฌํ˜„์„ ์™„๋ฃŒํ•œ ํ›„ GitHub์„ ํ†ตํ•ด ์ œ์ถœํ•ด์•ผ ํ•œ๋‹ค. - - GitHub์„ ํ™œ์šฉํ•œ ์ œ์ถœ ๋ฐฉ๋ฒ•์€ [ํ”„๋ฆฌ์ฝ”์Šค ๊ณผ์ œ ์ œ์ถœ](https://github.com/woowacourse/woowacourse-docs/tree/master/precourse) ๋ฌธ์„œ๋ฅผ ์ฐธ๊ณ ํ•ด - ์ œ์ถœํ•œ๋‹ค. -- GitHub์— ๋ฏธ์…˜์„ ์ œ์ถœํ•œ ํ›„ [์šฐ์•„ํ•œํ…Œํฌ์ฝ”์Šค ์ง€์›](https://apply.techcourse.co.kr) ์‚ฌ์ดํŠธ์— ์ ‘์†ํ•˜์—ฌ ํ”„๋ฆฌ์ฝ”์Šค ๊ณผ์ œ๋ฅผ ์ œ์ถœํ•œ๋‹ค. - - ์ž์„ธํ•œ ๋ฐฉ๋ฒ•์€ [์ œ์ถœ ๊ฐ€์ด๋“œ](https://github.com/woowacourse/woowacourse-docs/tree/master/precourse#์ œ์ถœ-๊ฐ€์ด๋“œ) ์ฐธ๊ณ  - - **Pull Request๋งŒ ๋ณด๋‚ด๊ณ  ์ง€์› ํ”Œ๋žซํผ์—์„œ ๊ณผ์ œ๋ฅผ ์ œ์ถœํ•˜์ง€ ์•Š์œผ๋ฉด ์ตœ์ข… ์ œ์ถœํ•˜์ง€ ์•Š์€ ๊ฒƒ์œผ๋กœ ์ฒ˜๋ฆฌ๋˜๋‹ˆ ์ฃผ์˜ํ•œ๋‹ค.** +[๊ตฌ๋งค] -## ๐Ÿšจ ๊ณผ์ œ ์ œ์ถœ ์ „ ์ฒดํฌ ๋ฆฌ์ŠคํŠธ - 0์  ๋ฐฉ์ง€ +- [ ] ๊ตฌ๋งค ๊ธˆ์•ก ์ž…๋ ฅ๋ฐ›๊ธฐ +- [ ] ๊ตฌ๋งค ๊ธˆ์•ก์ด ์ˆซ์ž ์•„๋‹ ์‹œ ์˜ˆ์™ธ ์ฒ˜๋ฆฌ +- [ ] ๊ตฌ๋งค ๊ธˆ์•ก 1000์› ๋‹จ์œ„๊ฐ€ ์•„๋‹ ์‹œ ์˜ˆ์™ธ ์ฒ˜๋ฆฌ +- [ ] ๊ตฌ๋งค ์žฅ์ˆ˜์— ํ•ด๋‹นํ•˜๋Š” ํšŸ์ˆ˜ ๋งŒํผ ๋‹น์ฒจ ๋ฒˆํ˜ธ ๋ฐ ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ ์ž…๋ ฅ ๋ฐ›๊ธฐ +- [ ] ๋ฒˆํ˜ธ๊ฐ€ ์ˆซ์ž๊ฐ€ ์•„๋‹ ๊ฒฝ์šฐ ์˜ˆ์™ธ ์ฒ˜๋ฆฌ -- ๊ธฐ๋Šฅ ๊ตฌํ˜„์„ ๋ชจ๋‘ ์ •์ƒ์ ์œผ๋กœ ํ–ˆ๋”๋ผ๋„ **์š”๊ตฌ ์‚ฌํ•ญ์— ๋ช…์‹œ๋œ ์ถœ๋ ฅ๊ฐ’ ํ˜•์‹์„ ์ง€ํ‚ค์ง€ ์•Š์„ ๊ฒฝ์šฐ 0์ ์œผ๋กœ ์ฒ˜๋ฆฌ**ํ•œ๋‹ค. -- ๊ธฐ๋Šฅ ๊ตฌํ˜„์„ ์™„๋ฃŒํ•œ ๋’ค ์•„๋ž˜ ๊ฐ€์ด๋“œ์— ๋”ฐ๋ผ ํ…Œ์ŠคํŠธ๋ฅผ ์‹คํ–‰ํ–ˆ์„ ๋•Œ ๋ชจ๋“  ํ…Œ์ŠคํŠธ๊ฐ€ ์„ฑ๊ณตํ•˜๋Š”์ง€ ํ™•์ธํ•œ๋‹ค. -- **ํ…Œ์ŠคํŠธ๊ฐ€ ์‹คํŒจํ•  ๊ฒฝ์šฐ 0์ ์œผ๋กœ ์ฒ˜๋ฆฌ**๋˜๋ฏ€๋กœ, ๋ฐ˜๋“œ์‹œ ํ™•์ธ ํ›„ ์ œ์ถœํ•œ๋‹ค. +[๊ฒฐ๊ณผ ์ถœ๋ ฅ] -### ํ…Œ์ŠคํŠธ ์‹คํ–‰ ๊ฐ€์ด๋“œ +- [ ] ๋ฐœํ–‰ํ•œ ๋กœ๋˜ ์ˆ˜๋Ÿ‰ ๋ฐ ๋ฒˆํ˜ธ๋ฅผ ์ถœ๋ ฅ +- [ ] ๋‹น์ฒจ ๋‚ด์—ญ ์ถœ๋ ฅ +- [ ] ์ˆ˜์ต๋ฅ  ์ถœ๋ ฅ -- ํ…Œ์ŠคํŠธ ํŒจํ‚ค์ง€ ์„ค์น˜๋ฅผ ์œ„ํ•ด `Node.js` ๋ฒ„์ „ `18.17.1` ์ด์ƒ์ด ํ•„์š”ํ•˜๋‹ค. -- ๋‹ค์Œ ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•ด ํŒจํ‚ค์ง€๋ฅผ ์„ค์น˜ํ•œ๋‹ค. - -```bash -npm install -``` - -- ์„ค์น˜๊ฐ€ ์™„๋ฃŒ๋˜์—ˆ๋‹ค๋ฉด, ๋‹ค์Œ ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•ด ํ…Œ์ŠคํŠธ๋ฅผ ์‹คํ–‰ํ•œ๋‹ค. - -```bash -npm test -``` - ---- - -## ๐Ÿš€ ๊ธฐ๋Šฅ ์š”๊ตฌ ์‚ฌํ•ญ - -- ๋กœ๋˜ ๊ฒŒ์ž„ ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ•ด์•ผ ํ•œ๋‹ค. ๋กœ๋˜ ๊ฒŒ์ž„์€ ์•„๋ž˜์™€ ๊ฐ™์€ ๊ทœ์น™์œผ๋กœ ์ง„ํ–‰๋œ๋‹ค. - -``` -- ๋กœ๋˜ ๋ฒˆํ˜ธ์˜ ์ˆซ์ž ๋ฒ”์œ„๋Š” 1~45๊นŒ์ง€์ด๋‹ค. -- 1๊ฐœ์˜ ๋กœ๋˜๋ฅผ ๋ฐœํ–‰ํ•  ๋•Œ ์ค‘๋ณต๋˜์ง€ ์•Š๋Š” 6๊ฐœ์˜ ์ˆซ์ž๋ฅผ ๋ฝ‘๋Š”๋‹ค. -- ๋‹น์ฒจ ๋ฒˆํ˜ธ ์ถ”์ฒจ ์‹œ ์ค‘๋ณต๋˜์ง€ ์•Š๋Š” ์ˆซ์ž 6๊ฐœ์™€ ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ 1๊ฐœ๋ฅผ ๋ฝ‘๋Š”๋‹ค. -- ๋‹น์ฒจ์€ 1๋“ฑ๋ถ€ํ„ฐ 5๋“ฑ๊นŒ์ง€ ์žˆ๋‹ค. ๋‹น์ฒจ ๊ธฐ์ค€๊ณผ ๊ธˆ์•ก์€ ์•„๋ž˜์™€ ๊ฐ™๋‹ค. - - 1๋“ฑ: 6๊ฐœ ๋ฒˆํ˜ธ ์ผ์น˜ / 2,000,000,000์› - - 2๋“ฑ: 5๊ฐœ ๋ฒˆํ˜ธ + ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ ์ผ์น˜ / 30,000,000์› - - 3๋“ฑ: 5๊ฐœ ๋ฒˆํ˜ธ ์ผ์น˜ / 1,500,000์› - - 4๋“ฑ: 4๊ฐœ ๋ฒˆํ˜ธ ์ผ์น˜ / 50,000์› - - 5๋“ฑ: 3๊ฐœ ๋ฒˆํ˜ธ ์ผ์น˜ / 5,000์› -``` - -- ๋กœ๋˜ ๊ตฌ์ž… ๊ธˆ์•ก์„ ์ž…๋ ฅํ•˜๋ฉด ๊ตฌ์ž… ๊ธˆ์•ก์— ํ•ด๋‹นํ•˜๋Š” ๋งŒํผ ๋กœ๋˜๋ฅผ ๋ฐœํ–‰ํ•ด์•ผ ํ•œ๋‹ค. -- ๋กœ๋˜ 1์žฅ์˜ ๊ฐ€๊ฒฉ์€ 1,000์›์ด๋‹ค. -- ๋‹น์ฒจ ๋ฒˆํ˜ธ์™€ ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅ๋ฐ›๋Š”๋‹ค. -- ์‚ฌ์šฉ์ž๊ฐ€ ๊ตฌ๋งคํ•œ ๋กœ๋˜ ๋ฒˆํ˜ธ์™€ ๋‹น์ฒจ ๋ฒˆํ˜ธ๋ฅผ ๋น„๊ตํ•˜์—ฌ ๋‹น์ฒจ ๋‚ด์—ญ ๋ฐ ์ˆ˜์ต๋ฅ ์„ ์ถœ๋ ฅํ•˜๊ณ  ๋กœ๋˜ ๊ฒŒ์ž„์„ ์ข…๋ฃŒํ•œ๋‹ค. -- ์‚ฌ์šฉ์ž๊ฐ€ ์ž˜๋ชป๋œ ๊ฐ’์„ ์ž…๋ ฅํ•  ๊ฒฝ์šฐ `throw`๋ฌธ์„ ์‚ฌ์šฉํ•ด ์˜ˆ์™ธ๋ฅผ ๋ฐœ์ƒ์‹œํ‚จ๋‹ค. ๊ทธ๋Ÿฐ ๋‹ค์Œ, "[ERROR]"๋กœ ์‹œ์ž‘ํ•˜๋Š” ์—๋Ÿฌ ๋ฉ”์‹œ์ง€๋ฅผ ์ถœ๋ ฅํ•˜๊ณ  ํ•ด๋‹น ๋ถ€๋ถ„๋ถ€ํ„ฐ ์ž…๋ ฅ์„ ๋‹ค์‹œ ๋ฐ›๋Š”๋‹ค. - ``` - ์˜ˆ์‹œ) [ERROR] ์ˆซ์ž๊ฐ€ ์ž˜๋ชป๋œ ํ˜•์‹์ž…๋‹ˆ๋‹ค. - ``` - -### ์ž…์ถœ๋ ฅ ์š”๊ตฌ ์‚ฌํ•ญ - -#### ์ž…๋ ฅ - -- ๋กœ๋˜ ๊ตฌ์ž… ๊ธˆ์•ก์„ ์ž…๋ ฅ ๋ฐ›๋Š”๋‹ค. ๊ตฌ์ž… ๊ธˆ์•ก์€ 1,000์› ๋‹จ์œ„๋กœ ์ž…๋ ฅ ๋ฐ›์œผ๋ฉฐ 1,000์›์œผ๋กœ ๋‚˜๋ˆ„์–ด ๋–จ์–ด์ง€์ง€ ์•Š๋Š” ๊ฒฝ์šฐ ์˜ˆ์™ธ ์ฒ˜๋ฆฌํ•œ๋‹ค. - -``` -14000 -``` - -- ๋‹น์ฒจ ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅ ๋ฐ›๋Š”๋‹ค. ๋ฒˆํ˜ธ๋Š” ์‰ผํ‘œ(,)๋ฅผ ๊ธฐ์ค€์œผ๋กœ ๊ตฌ๋ถ„ํ•œ๋‹ค. - -``` -1,2,3,4,5,6 -``` - -- ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅ ๋ฐ›๋Š”๋‹ค. - -``` -7 -``` - -#### ์ถœ๋ ฅ - -- ๋ฐœํ–‰ํ•œ ๋กœ๋˜ ์ˆ˜๋Ÿ‰ ๋ฐ ๋ฒˆํ˜ธ๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค. ๋กœ๋˜ ๋ฒˆํ˜ธ๋Š” ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌํ•˜์—ฌ ๋ณด์—ฌ์ค€๋‹ค. - -``` -8๊ฐœ๋ฅผ ๊ตฌ๋งคํ–ˆ์Šต๋‹ˆ๋‹ค. -[8, 21, 23, 41, 42, 43] -[3, 5, 11, 16, 32, 38] -[7, 11, 16, 35, 36, 44] -[1, 8, 11, 31, 41, 42] -[13, 14, 16, 38, 42, 45] -[7, 11, 30, 40, 42, 43] -[2, 13, 22, 32, 38, 45] -[1, 3, 5, 14, 22, 45] -``` - -- ๋‹น์ฒจ ๋‚ด์—ญ์„ ์ถœ๋ ฅํ•œ๋‹ค. - -``` -3๊ฐœ ์ผ์น˜ (5,000์›) - 1๊ฐœ -4๊ฐœ ์ผ์น˜ (50,000์›) - 0๊ฐœ -5๊ฐœ ์ผ์น˜ (1,500,000์›) - 0๊ฐœ -5๊ฐœ ์ผ์น˜, ๋ณด๋„ˆ์Šค ๋ณผ ์ผ์น˜ (30,000,000์›) - 0๊ฐœ -6๊ฐœ ์ผ์น˜ (2,000,000,000์›) - 0๊ฐœ -``` - -- ์ˆ˜์ต๋ฅ ์€ ์†Œ์ˆ˜์  ๋‘˜์งธ ์ž๋ฆฌ์—์„œ ๋ฐ˜์˜ฌ๋ฆผํ•œ๋‹ค. (ex. 100.0%, 51.5%, 1,000,000.0%) - -``` -์ด ์ˆ˜์ต๋ฅ ์€ 62.5%์ž…๋‹ˆ๋‹ค. -``` - -- ์˜ˆ์™ธ ์ƒํ™ฉ ์‹œ ์—๋Ÿฌ ๋ฌธ๊ตฌ๋ฅผ ์ถœ๋ ฅํ•ด์•ผ ํ•œ๋‹ค. ๋‹จ, ์—๋Ÿฌ ๋ฌธ๊ตฌ๋Š” "[ERROR]"๋กœ ์‹œ์ž‘ํ•ด์•ผ ํ•œ๋‹ค. - -``` -[ERROR] ๋กœ๋˜ ๋ฒˆํ˜ธ๋Š” 1๋ถ€ํ„ฐ 45 ์‚ฌ์ด์˜ ์ˆซ์ž์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค. -``` - -#### ์‹คํ–‰ ๊ฒฐ๊ณผ ์˜ˆ์‹œ +## ์‹คํ–‰ ์˜ˆ์‹œ ``` ๊ตฌ์ž…๊ธˆ์•ก์„ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”. @@ -157,83 +55,6 @@ npm test --- -## ๐ŸŽฏ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์š”๊ตฌ ์‚ฌํ•ญ - -- Node.js 18.17.1 ๋ฒ„์ „์—์„œ ์‹คํ–‰ ๊ฐ€๋Šฅํ•ด์•ผ ํ•œ๋‹ค. **Node.js 18.17.1์—์„œ ์ •์ƒ์ ์œผ๋กœ ๋™์ž‘ํ•˜์ง€ ์•Š์„ ๊ฒฝ์šฐ 0์  ์ฒ˜๋ฆฌํ•œ๋‹ค.** -- ํ”„๋กœ๊ทธ๋žจ ์‹คํ–‰์˜ ์‹œ์ž‘์ ์€ `App.js`์˜ `play` ๋ฉ”์„œ๋“œ์ด๋‹ค. ์•„๋ž˜์™€ ๊ฐ™์ด ํ”„๋กœ๊ทธ๋žจ์„ ์‹คํ–‰์‹œํ‚ฌ ์ˆ˜ ์žˆ์–ด์•ผ ํ•œ๋‹ค. - -**์˜ˆ์‹œ** - -```javascript -const app = new App(); -app.play(); ``` -- `package.json`์„ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์—†๊ณ  ์™ธ๋ถ€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ(jQuery, Lodash ๋“ฑ)๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š”๋‹ค. ์ˆœ์ˆ˜ Vanilla JS๋กœ๋งŒ ๊ตฌํ˜„ํ•œ๋‹ค. -- [JavaScript ์ฝ”๋“œ ์ปจ๋ฒค์…˜](https://github.com/woowacourse/woowacourse-docs/tree/main/styleguide/javascript)์„ ์ง€ํ‚ค๋ฉด์„œ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ํ•œ๋‹ค -- ํ”„๋กœ๊ทธ๋žจ ์ข…๋ฃŒ ์‹œ `process.exit()`๋ฅผ ํ˜ธ์ถœํ•˜์ง€ ์•Š๋Š”๋‹ค. -- ํ”„๋กœ๊ทธ๋žจ ๊ตฌํ˜„์ด ์™„๋ฃŒ๋˜๋ฉด `ApplicationTest`์˜ ๋ชจ๋“  ํ…Œ์ŠคํŠธ๊ฐ€ ์„ฑ๊ณตํ•ด์•ผ ํ•œ๋‹ค. **ํ…Œ์ŠคํŠธ๊ฐ€ ์‹คํŒจํ•  ๊ฒฝ์šฐ 0์  ์ฒ˜๋ฆฌํ•œ๋‹ค.** -- ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์š”๊ตฌ ์‚ฌํ•ญ์—์„œ ๋‹ฌ๋ฆฌ ๋ช…์‹œํ•˜์ง€ ์•Š๋Š” ํ•œ ํŒŒ์ผ, ํŒจํ‚ค์ง€ ์ด๋ฆ„์„ ์ˆ˜์ •ํ•˜๊ฑฐ๋‚˜ ์ด๋™ํ•˜์ง€ ์•Š๋Š”๋‹ค. -- indent(์ธ๋ดํŠธ, ๋“ค์—ฌ์“ฐ๊ธฐ) depth๋ฅผ 3์ด ๋„˜์ง€ ์•Š๋„๋ก ๊ตฌํ˜„ํ•œ๋‹ค. 2๊นŒ์ง€๋งŒ ํ—ˆ์šฉํ•œ๋‹ค. - - ์˜ˆ๋ฅผ ๋“ค์–ด while๋ฌธ ์•ˆ์— if๋ฌธ์ด ์žˆ์œผ๋ฉด ๋“ค์—ฌ์“ฐ๊ธฐ๋Š” 2์ด๋‹ค. - - ํžŒํŠธ: indent(์ธ๋ดํŠธ, ๋“ค์—ฌ์“ฐ๊ธฐ) depth๋ฅผ ์ค„์ด๋Š” ์ข‹์€ ๋ฐฉ๋ฒ•์€ ํ•จ์ˆ˜(๋˜๋Š” ๋ฉ”์„œ๋“œ)๋ฅผ ๋ถ„๋ฆฌํ•˜๋ฉด ๋œ๋‹ค. -- ํ•จ์ˆ˜(๋˜๋Š” ๋ฉ”์„œ๋“œ)๊ฐ€ ํ•œ ๊ฐ€์ง€ ์ผ๋งŒ ํ•˜๋„๋ก ์ตœ๋Œ€ํ•œ ์ž‘๊ฒŒ ๋งŒ๋“ค์–ด๋ผ. -- Jest๋ฅผ ์ด์šฉํ•˜์—ฌ ๋ณธ์ธ์ด ์ •๋ฆฌํ•œ ๊ธฐ๋Šฅ ๋ชฉ๋ก์ด ์ •์ƒ ๋™์ž‘ํ•จ์„ ํ…Œ์ŠคํŠธ ์ฝ”๋“œ๋กœ ํ™•์ธํ•œ๋‹ค. - -### ์ถ”๊ฐ€๋œ ์š”๊ตฌ ์‚ฌํ•ญ - -- ํ•จ์ˆ˜(๋˜๋Š” ๋ฉ”์„œ๋“œ)์˜ ๊ธธ์ด๊ฐ€ 15๋ผ์ธ์„ ๋„˜์–ด๊ฐ€์ง€ ์•Š๋„๋ก ๊ตฌํ˜„ํ•œ๋‹ค. - - ํ•จ์ˆ˜(๋˜๋Š” ๋ฉ”์„œ๋“œ)๊ฐ€ ํ•œ ๊ฐ€์ง€ ์ผ๋งŒ ์ž˜ ํ•˜๋„๋ก ๊ตฌํ˜„ํ•œ๋‹ค. -- else๋ฅผ ์ง€์–‘ํ•œ๋‹ค. - - ํžŒํŠธ: if ์กฐ๊ฑด์ ˆ์—์„œ ๊ฐ’์„ returnํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ๊ตฌํ˜„ํ•˜๋ฉด else๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š์•„๋„ ๋œ๋‹ค. - - ๋•Œ๋กœ๋Š” if/else, switch๋ฌธ์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ๋” ๊น”๋”ํ•ด ๋ณด์ผ ์ˆ˜ ์žˆ๋‹ค. ์–ด๋Š ๊ฒฝ์šฐ์— ์“ฐ๋Š” ๊ฒƒ์ด ์ ์ ˆํ• ์ง€ ์Šค์Šค๋กœ ๊ณ ๋ฏผํ•ด ๋ณธ๋‹ค. -- ๋„๋ฉ”์ธ ๋กœ์ง์— ๋‹จ์œ„ ํ…Œ์ŠคํŠธ๋ฅผ ๊ตฌํ˜„ํ•ด์•ผ ํ•œ๋‹ค. ๋‹จ, UI(Console.readLineAsync, Console.print) ๋กœ์ง์— ๋Œ€ํ•œ ๋‹จ์œ„ ํ…Œ์ŠคํŠธ๋Š” ์ œ์™ธํ•œ๋‹ค. - - ํ•ต์‹ฌ ๋กœ์ง์„ ๊ตฌํ˜„ํ•˜๋Š” ์ฝ”๋“œ์™€ UI๋ฅผ ๋‹ด๋‹นํ•˜๋Š” ๋กœ์ง์„ ๊ตฌ๋ถ„ํ•œ๋‹ค. - - ๋‹จ์œ„ ํ…Œ์ŠคํŠธ ์ž‘์„ฑ์ด ์ต์ˆ™ํ•˜์ง€ ์•Š๋‹ค๋ฉด `__tests__/LottoTest.js`๋ฅผ ์ฐธ๊ณ ํ•˜์—ฌ ํ•™์Šตํ•œ ํ›„ ํ…Œ์ŠคํŠธ๋ฅผ ๊ตฌํ˜„ํ•œ๋‹ค. - -### ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ - -- `@woowacourse/mission-utils`์—์„œ ์ œ๊ณตํ•˜๋Š” `Random` ๋ฐ `Console` API๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๊ตฌํ˜„ํ•ด์•ผ ํ•œ๋‹ค. - - Random ๊ฐ’ ์ถ”์ถœ์€ `Random.pickUniqueNumbersInRange()`๋ฅผ ํ™œ์šฉํ•œ๋‹ค. - - ์‚ฌ์šฉ์ž์˜ ๊ฐ’์„ ์ž…๋ ฅ ๋ฐ›๊ณ  ์ถœ๋ ฅํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” `Console.readLineAsync`, `Console.print`๋ฅผ ํ™œ์šฉํ•œ๋‹ค. - -#### ์‚ฌ์šฉ ์˜ˆ์‹œ - -```javascript -MissionUtils.Random.pickUniqueNumbersInRange(1, 45, 6); ``` - -### Lotto ํด๋ž˜์Šค - -- ์ œ๊ณต๋œ `Lotto` ํด๋ž˜์Šค๋ฅผ ํ™œ์šฉํ•ด ๊ตฌํ˜„ํ•ด์•ผ ํ•œ๋‹ค. -- `numbers`์˜ `#` prefix๋ฅผ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์—†๋‹ค. -- `Lotto`์— ํ•„๋“œ๋ฅผ ์ถ”๊ฐ€ํ•  ์ˆ˜ ์—†๋‹ค. - -```javascript -class Lotto { - #numbers; - - constructor(numbers) { - this.#validate(numbers); - this.#numbers = numbers; - } - - #validate(numbers) { - if (numbers.length !== 6) { - throw new Error("[ERROR] ๋กœ๋˜ ๋ฒˆํ˜ธ๋Š” 6๊ฐœ์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค."); - } - } - - // TODO: ์ถ”๊ฐ€ ๊ธฐ๋Šฅ ๊ตฌํ˜„ -} -``` - ---- - -## โœ๏ธ ๊ณผ์ œ ์ง„ํ–‰ ์š”๊ตฌ ์‚ฌํ•ญ - -- ๋ฏธ์…˜์€ [javascript-lotto-6](https://github.com/woowacourse-precourse/javascript-lotto-6/) ์ €์žฅ์†Œ๋ฅผ Fork & Cloneํ•ด ์‹œ์ž‘ํ•œ๋‹ค. -- **๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ•˜๊ธฐ ์ „ `docs/README.md`์— ๊ตฌํ˜„ํ•  ๊ธฐ๋Šฅ ๋ชฉ๋ก์„ ์ •๋ฆฌ**ํ•ด ์ถ”๊ฐ€ํ•œ๋‹ค. -- **Git์˜ ์ปค๋ฐ‹ ๋‹จ์œ„๋Š” ์•ž ๋‹จ๊ณ„์—์„œ `docs/README.md`์— ์ •๋ฆฌํ•œ ๊ธฐ๋Šฅ ๋ชฉ๋ก ๋‹จ์œ„**๋กœ ์ถ”๊ฐ€ํ•œ๋‹ค. - - [์ปค๋ฐ‹ ๋ฉ”์‹œ์ง€ ์ปจ๋ฒค์…˜](https://gist.github.com/stephenparish/9941e89d80e2bc58a153) ๊ฐ€์ด๋“œ๋ฅผ ์ฐธ๊ณ ํ•ด ์ปค๋ฐ‹ ๋ฉ”์‹œ์ง€๋ฅผ ์ž‘์„ฑํ•œ๋‹ค. -- ๊ณผ์ œ ์ง„ํ–‰ ๋ฐ ์ œ์ถœ ๋ฐฉ๋ฒ•์€ [ํ”„๋ฆฌ์ฝ”์Šค ๊ณผ์ œ ์ œ์ถœ](https://github.com/woowacourse/woowacourse-docs/tree/master/precourse) ๋ฌธ์„œ๋ฅผ ์ฐธ๊ณ ํ•œ๋‹ค. From 5080c87497e779feeafc9e73e1ba12c77360f570 Mon Sep 17 00:00:00 2001 From: nari Date: Wed, 8 Nov 2023 00:48:15 +0900 Subject: [PATCH 02/17] =?UTF-8?q?fix=20:=20README=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EB=AA=A9=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fd9176f68e..ce428f520b 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ - [ ] ๊ตฌ๋งค ๊ธˆ์•ก ์ž…๋ ฅ๋ฐ›๊ธฐ - [ ] ๊ตฌ๋งค ๊ธˆ์•ก์ด ์ˆซ์ž ์•„๋‹ ์‹œ ์˜ˆ์™ธ ์ฒ˜๋ฆฌ - [ ] ๊ตฌ๋งค ๊ธˆ์•ก 1000์› ๋‹จ์œ„๊ฐ€ ์•„๋‹ ์‹œ ์˜ˆ์™ธ ์ฒ˜๋ฆฌ -- [ ] ๊ตฌ๋งค ์žฅ์ˆ˜์— ํ•ด๋‹นํ•˜๋Š” ํšŸ์ˆ˜ ๋งŒํผ ๋‹น์ฒจ ๋ฒˆํ˜ธ ๋ฐ ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ ์ž…๋ ฅ ๋ฐ›๊ธฐ +- [ ] ๋‹น์ฒจ ๋ฒˆํ˜ธ ๋ฐ ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ ์ž…๋ ฅ ๋ฐ›๊ธฐ - [ ] ๋ฒˆํ˜ธ๊ฐ€ ์ˆซ์ž๊ฐ€ ์•„๋‹ ๊ฒฝ์šฐ ์˜ˆ์™ธ ์ฒ˜๋ฆฌ [๊ฒฐ๊ณผ ์ถœ๋ ฅ] From 49ca775b4999e4b88e0bd5e47d8e9831d2e492ad Mon Sep 17 00:00:00 2001 From: nari Date: Wed, 8 Nov 2023 00:58:59 +0900 Subject: [PATCH 03/17] =?UTF-8?q?feat=20:=20=EA=B5=AC=EB=A7=A4=20=EA=B8=88?= =?UTF-8?q?=EC=95=A1=20=EC=9E=85=EB=A0=A5=EB=B0=9B=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- src/App.js | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ce428f520b..e8c0c23d74 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ [๊ตฌ๋งค] -- [ ] ๊ตฌ๋งค ๊ธˆ์•ก ์ž…๋ ฅ๋ฐ›๊ธฐ +- [x] ๊ตฌ๋งค ๊ธˆ์•ก ์ž…๋ ฅ๋ฐ›๊ธฐ - [ ] ๊ตฌ๋งค ๊ธˆ์•ก์ด ์ˆซ์ž ์•„๋‹ ์‹œ ์˜ˆ์™ธ ์ฒ˜๋ฆฌ - [ ] ๊ตฌ๋งค ๊ธˆ์•ก 1000์› ๋‹จ์œ„๊ฐ€ ์•„๋‹ ์‹œ ์˜ˆ์™ธ ์ฒ˜๋ฆฌ - [ ] ๋‹น์ฒจ ๋ฒˆํ˜ธ ๋ฐ ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ ์ž…๋ ฅ ๋ฐ›๊ธฐ diff --git a/src/App.js b/src/App.js index c38b30d5b2..eff5c39d1f 100644 --- a/src/App.js +++ b/src/App.js @@ -1,5 +1,9 @@ class App { - async play() {} + async play() { + //๊ตฌ์ž… ๊ธˆ์•ก ์ž…๋ ฅ๋ฐ›๊ธฐ + MissionUtils.Console.print("๊ตฌ์ž…๊ธˆ์•ก์„ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."); + const totalCost = await MissionUtils.Console.readLineAsync(""); + } } export default App; From ccce2d76005c36a8bc04b0732497dd18c52d6d8d Mon Sep 17 00:00:00 2001 From: nari Date: Wed, 8 Nov 2023 01:04:27 +0900 Subject: [PATCH 04/17] =?UTF-8?q?feat=20:=20=EA=B5=AC=EC=9E=85=20=EA=B8=88?= =?UTF-8?q?=EC=95=A1=EC=9D=B4=20=EC=88=AB=EC=9E=90=20=EC=95=84=EB=8B=90=20?= =?UTF-8?q?=EB=95=8C=20=EC=98=88=EC=99=B8=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- src/App.js | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e8c0c23d74..a1b6f92ba1 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ [๊ตฌ๋งค] - [x] ๊ตฌ๋งค ๊ธˆ์•ก ์ž…๋ ฅ๋ฐ›๊ธฐ -- [ ] ๊ตฌ๋งค ๊ธˆ์•ก์ด ์ˆซ์ž ์•„๋‹ ์‹œ ์˜ˆ์™ธ ์ฒ˜๋ฆฌ +- [x] ๊ตฌ๋งค ๊ธˆ์•ก์ด ์ˆซ์ž ์•„๋‹ ์‹œ ์˜ˆ์™ธ ์ฒ˜๋ฆฌ - [ ] ๊ตฌ๋งค ๊ธˆ์•ก 1000์› ๋‹จ์œ„๊ฐ€ ์•„๋‹ ์‹œ ์˜ˆ์™ธ ์ฒ˜๋ฆฌ - [ ] ๋‹น์ฒจ ๋ฒˆํ˜ธ ๋ฐ ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ ์ž…๋ ฅ ๋ฐ›๊ธฐ - [ ] ๋ฒˆํ˜ธ๊ฐ€ ์ˆซ์ž๊ฐ€ ์•„๋‹ ๊ฒฝ์šฐ ์˜ˆ์™ธ ์ฒ˜๋ฆฌ diff --git a/src/App.js b/src/App.js index eff5c39d1f..ee31c6a522 100644 --- a/src/App.js +++ b/src/App.js @@ -3,6 +3,11 @@ class App { //๊ตฌ์ž… ๊ธˆ์•ก ์ž…๋ ฅ๋ฐ›๊ธฐ MissionUtils.Console.print("๊ตฌ์ž…๊ธˆ์•ก์„ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."); const totalCost = await MissionUtils.Console.readLineAsync(""); + + //๊ตฌ์ž… ๊ธˆ์•ก ์˜ˆ์™ธ ์ฒ˜๋ฆฌ - 1) ์ˆซ์ž๊ฐ€ ์•„๋‹ ๋•Œ + if (Number.isNaN(totalCost) === true) { + throw new Error("[ERROR] ์ˆซ์ž๋ฅผ ์ž…๋ ฅํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค."); + } } } From 375e71335af80c77538764d9497c86b32ddc7de3 Mon Sep 17 00:00:00 2001 From: nari Date: Wed, 8 Nov 2023 01:19:31 +0900 Subject: [PATCH 05/17] =?UTF-8?q?feat=20:=20=EA=B5=AC=EB=A7=A4=20=EA=B8=88?= =?UTF-8?q?=EC=95=A1=201000=EC=9B=90=20=EB=8B=A8=EC=9C=84=EA=B0=80=20?= =?UTF-8?q?=EC=95=84=EB=8B=90=20=EC=8B=9C=20=EC=98=88=EC=99=B8=20=EC=B2=98?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/App.js b/src/App.js index ee31c6a522..01a87111a0 100644 --- a/src/App.js +++ b/src/App.js @@ -1,13 +1,21 @@ +import { MissionUtils } from "@woowacourse/mission-utils"; + class App { async play() { //๊ตฌ์ž… ๊ธˆ์•ก ์ž…๋ ฅ๋ฐ›๊ธฐ MissionUtils.Console.print("๊ตฌ์ž…๊ธˆ์•ก์„ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."); const totalCost = await MissionUtils.Console.readLineAsync(""); + MissionUtils.Console.print("๊ตฌ์ž…๊ธˆ์•ก์„ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."); //๊ตฌ์ž… ๊ธˆ์•ก ์˜ˆ์™ธ ์ฒ˜๋ฆฌ - 1) ์ˆซ์ž๊ฐ€ ์•„๋‹ ๋•Œ if (Number.isNaN(totalCost) === true) { throw new Error("[ERROR] ์ˆซ์ž๋ฅผ ์ž…๋ ฅํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค."); } + + //๊ตฌ์ž… ๊ธˆ์•ก ์˜ˆ์™ธ ์ฒ˜๋ฆฌ - 2) 1000์› ๋‹จ์œ„๊ฐ€ ์•„๋‹ ๋•Œ + if (Number(totalCost) % 1000 !== 0) { + throw new Error("[ERROR] 1000์› ๋‹จ์œ„ ๊ธˆ์•ก์„ ์ž…๋ ฅํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค."); + } } } From 7c68813605ee5128f19c32fe55eb43a79ad3ff0b Mon Sep 17 00:00:00 2001 From: nari Date: Wed, 8 Nov 2023 01:20:21 +0900 Subject: [PATCH 06/17] =?UTF-8?q?fix=20:=20=EA=B5=AC=EC=9E=85=20=EA=B8=88?= =?UTF-8?q?=EC=95=A1=20=EC=88=AB=EC=9E=90=20=EC=95=84=EB=8B=90=20=EB=95=8C?= =?UTF-8?q?=20=EC=98=88=EC=99=B8=EC=B2=98=EB=A6=AC=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/App.js b/src/App.js index 01a87111a0..c0e6d75673 100644 --- a/src/App.js +++ b/src/App.js @@ -8,7 +8,7 @@ class App { MissionUtils.Console.print("๊ตฌ์ž…๊ธˆ์•ก์„ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."); //๊ตฌ์ž… ๊ธˆ์•ก ์˜ˆ์™ธ ์ฒ˜๋ฆฌ - 1) ์ˆซ์ž๊ฐ€ ์•„๋‹ ๋•Œ - if (Number.isNaN(totalCost) === true) { + if (isNaN(totalCost) === true) { throw new Error("[ERROR] ์ˆซ์ž๋ฅผ ์ž…๋ ฅํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค."); } From aa9a24497405a1e0cba1f07ccba42ed99ce7a4c0 Mon Sep 17 00:00:00 2001 From: nari Date: Wed, 8 Nov 2023 01:31:55 +0900 Subject: [PATCH 07/17] =?UTF-8?q?feat=20:=20=EB=9E=9C=EB=8D=A4=20=EC=88=AB?= =?UTF-8?q?=EC=9E=90=EB=A1=9C=20=EB=A1=9C=EB=98=90=20=EB=B0=9C=ED=96=89=20?= =?UTF-8?q?=EB=B0=8F=20=EA=B2=B0=EA=B3=BC=20=EC=B6=9C=EB=A0=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 ++-- src/App.js | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a1b6f92ba1..f1e14e91f4 100644 --- a/README.md +++ b/README.md @@ -11,13 +11,13 @@ - [x] ๊ตฌ๋งค ๊ธˆ์•ก ์ž…๋ ฅ๋ฐ›๊ธฐ - [x] ๊ตฌ๋งค ๊ธˆ์•ก์ด ์ˆซ์ž ์•„๋‹ ์‹œ ์˜ˆ์™ธ ์ฒ˜๋ฆฌ -- [ ] ๊ตฌ๋งค ๊ธˆ์•ก 1000์› ๋‹จ์œ„๊ฐ€ ์•„๋‹ ์‹œ ์˜ˆ์™ธ ์ฒ˜๋ฆฌ +- [x] ๊ตฌ๋งค ๊ธˆ์•ก 1000์› ๋‹จ์œ„๊ฐ€ ์•„๋‹ ์‹œ ์˜ˆ์™ธ ์ฒ˜๋ฆฌ - [ ] ๋‹น์ฒจ ๋ฒˆํ˜ธ ๋ฐ ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ ์ž…๋ ฅ ๋ฐ›๊ธฐ - [ ] ๋ฒˆํ˜ธ๊ฐ€ ์ˆซ์ž๊ฐ€ ์•„๋‹ ๊ฒฝ์šฐ ์˜ˆ์™ธ ์ฒ˜๋ฆฌ [๊ฒฐ๊ณผ ์ถœ๋ ฅ] -- [ ] ๋ฐœํ–‰ํ•œ ๋กœ๋˜ ์ˆ˜๋Ÿ‰ ๋ฐ ๋ฒˆํ˜ธ๋ฅผ ์ถœ๋ ฅ +- [x] ๋žœ๋ค ์ˆซ์ž๋กœ ๋กœ๋˜ ๋ฐœํ–‰ ๋ฐ ๊ฒฐ๊ณผ(์ˆ˜๋Ÿ‰ ๋ฐ ๋ฒˆํ˜ธ) ์ถœ๋ ฅ - [ ] ๋‹น์ฒจ ๋‚ด์—ญ ์ถœ๋ ฅ - [ ] ์ˆ˜์ต๋ฅ  ์ถœ๋ ฅ diff --git a/src/App.js b/src/App.js index c0e6d75673..f3285ac374 100644 --- a/src/App.js +++ b/src/App.js @@ -5,7 +5,6 @@ class App { //๊ตฌ์ž… ๊ธˆ์•ก ์ž…๋ ฅ๋ฐ›๊ธฐ MissionUtils.Console.print("๊ตฌ์ž…๊ธˆ์•ก์„ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."); const totalCost = await MissionUtils.Console.readLineAsync(""); - MissionUtils.Console.print("๊ตฌ์ž…๊ธˆ์•ก์„ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."); //๊ตฌ์ž… ๊ธˆ์•ก ์˜ˆ์™ธ ์ฒ˜๋ฆฌ - 1) ์ˆซ์ž๊ฐ€ ์•„๋‹ ๋•Œ if (isNaN(totalCost) === true) { @@ -16,6 +15,20 @@ class App { if (Number(totalCost) % 1000 !== 0) { throw new Error("[ERROR] 1000์› ๋‹จ์œ„ ๊ธˆ์•ก์„ ์ž…๋ ฅํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค."); } + + // ๊ตฌ๋งค ๊ฐœ์ˆ˜ ๋งŒํผ ๋‹น์ฒจ ๋ฒˆํ˜ธ ์ƒ์„ฑ ๋ฐ ์ถœ๋ ฅ + const boughtLottoCount = totalCost / 1000; + const totalLottoNumList = []; + MissionUtils.Console.print(`${boughtLottoCount}๊ฐœ๋ฅผ ๊ตฌ๋งคํ–ˆ์Šต๋‹ˆ๋‹ค.`); + for (let i = 0; i < boughtLottoCount; i++) { + const nowLottoNumList = MissionUtils.Random.pickUniqueNumbersInRange( + 1, + 45, + 6 + ); + MissionUtils.Console.print(nowLottoNumList); + totalLottoNumList.push(nowLottoNumList); + } } } From e9a95a77b535173ef99f5cb59d10e313c9e481b0 Mon Sep 17 00:00:00 2001 From: nari Date: Wed, 8 Nov 2023 01:34:21 +0900 Subject: [PATCH 08/17] =?UTF-8?q?fix=20:=20=EA=B0=81=EC=A3=BC=20=EC=84=A4?= =?UTF-8?q?=EB=AA=85=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/App.js b/src/App.js index f3285ac374..f706439155 100644 --- a/src/App.js +++ b/src/App.js @@ -16,7 +16,7 @@ class App { throw new Error("[ERROR] 1000์› ๋‹จ์œ„ ๊ธˆ์•ก์„ ์ž…๋ ฅํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค."); } - // ๊ตฌ๋งค ๊ฐœ์ˆ˜ ๋งŒํผ ๋‹น์ฒจ ๋ฒˆํ˜ธ ์ƒ์„ฑ ๋ฐ ์ถœ๋ ฅ + // ๊ตฌ๋งค ๊ฐœ์ˆ˜ ๋งŒํผ ์ถ”์ฒจ ๋ฒˆํ˜ธ ์ƒ์„ฑ ๋ฐ ์ถœ๋ ฅ const boughtLottoCount = totalCost / 1000; const totalLottoNumList = []; MissionUtils.Console.print(`${boughtLottoCount}๊ฐœ๋ฅผ ๊ตฌ๋งคํ–ˆ์Šต๋‹ˆ๋‹ค.`); @@ -29,6 +29,8 @@ class App { MissionUtils.Console.print(nowLottoNumList); totalLottoNumList.push(nowLottoNumList); } + + // ๋‹น์ฒจ ๋ฒˆํ˜ธ ๋ฐ ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ ์ž…๋ ฅ ๋ฐ›๊ธฐ } } From a36a59ca0937bae4f2428478f656537b36021ff4 Mon Sep 17 00:00:00 2001 From: nari Date: Wed, 8 Nov 2023 01:45:48 +0900 Subject: [PATCH 09/17] =?UTF-8?q?feat=20:=20=EB=8B=B9=EC=B2=A8=20=EB=B2=88?= =?UTF-8?q?=ED=98=B8=20=EB=B0=8F=20=EB=B3=B4=EB=84=88=EC=8A=A4=20=EB=B2=88?= =?UTF-8?q?=ED=98=B8=20=EC=9E=85=EB=A0=A5=20=EB=B0=9B=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/App.js b/src/App.js index f706439155..9b10a41e56 100644 --- a/src/App.js +++ b/src/App.js @@ -31,6 +31,12 @@ class App { } // ๋‹น์ฒจ ๋ฒˆํ˜ธ ๋ฐ ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ ์ž…๋ ฅ ๋ฐ›๊ธฐ + MissionUtils.Console.print("๋‹น์ฒจ ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."); + const winnigNum = await MissionUtils.Console.readLineAsync(""); + const winningNumList = winnigNum.split(","); + + MissionUtils.Console.print("๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."); + const bonusNum = await MissionUtils.Console.readLineAsync(""); } } From e626abdc4e1d545941cb8871988a1920b404e480 Mon Sep 17 00:00:00 2001 From: nari Date: Wed, 8 Nov 2023 01:49:58 +0900 Subject: [PATCH 10/17] =?UTF-8?q?feat=20:=20=EB=A1=9C=EB=98=90=20=EB=8B=B9?= =?UTF-8?q?=EC=B2=A8=20=EB=B0=8F=20=EB=B3=B4=EB=84=88=EC=8A=A4=20=EB=B2=88?= =?UTF-8?q?=ED=98=B8=EA=B0=80=20=EC=88=AB=EC=9E=90=EA=B0=80=20=EC=95=84?= =?UTF-8?q?=EB=8B=90=20=EA=B2=BD=EC=9A=B0=20=EC=98=88=EC=99=B8=20=EC=B2=98?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 ++-- src/App.js | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f1e14e91f4..7195805182 100644 --- a/README.md +++ b/README.md @@ -12,8 +12,8 @@ - [x] ๊ตฌ๋งค ๊ธˆ์•ก ์ž…๋ ฅ๋ฐ›๊ธฐ - [x] ๊ตฌ๋งค ๊ธˆ์•ก์ด ์ˆซ์ž ์•„๋‹ ์‹œ ์˜ˆ์™ธ ์ฒ˜๋ฆฌ - [x] ๊ตฌ๋งค ๊ธˆ์•ก 1000์› ๋‹จ์œ„๊ฐ€ ์•„๋‹ ์‹œ ์˜ˆ์™ธ ์ฒ˜๋ฆฌ -- [ ] ๋‹น์ฒจ ๋ฒˆํ˜ธ ๋ฐ ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ ์ž…๋ ฅ ๋ฐ›๊ธฐ -- [ ] ๋ฒˆํ˜ธ๊ฐ€ ์ˆซ์ž๊ฐ€ ์•„๋‹ ๊ฒฝ์šฐ ์˜ˆ์™ธ ์ฒ˜๋ฆฌ +- [x] ๋‹น์ฒจ ๋ฒˆํ˜ธ ๋ฐ ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ ์ž…๋ ฅ ๋ฐ›๊ธฐ +- [x] ๋ฒˆํ˜ธ๊ฐ€ ์ˆซ์ž๊ฐ€ ์•„๋‹ ๊ฒฝ์šฐ ์˜ˆ์™ธ ์ฒ˜๋ฆฌ [๊ฒฐ๊ณผ ์ถœ๋ ฅ] diff --git a/src/App.js b/src/App.js index 9b10a41e56..872baa8657 100644 --- a/src/App.js +++ b/src/App.js @@ -37,6 +37,11 @@ class App { MissionUtils.Console.print("๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."); const bonusNum = await MissionUtils.Console.readLineAsync(""); + + //์ˆซ์ž ์•„๋‹ ์‹œ ์˜ˆ์™ธ ์ฒ˜๋ฆฌ + if (isNaN(winnigNum) === true || isNaN(bonusNum) === true) { + throw new Error("[ERROR] ์ˆซ์ž๋ฅผ ์ž…๋ ฅํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค."); + } } } From c29aa356c4246c8d70ed36f30e2683e3999b71db Mon Sep 17 00:00:00 2001 From: nari Date: Wed, 8 Nov 2023 21:50:12 +0900 Subject: [PATCH 11/17] =?UTF-8?q?feat=20:=20=EB=A1=9C=EB=98=90=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 ++ src/Lotto.js | 44 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7195805182..392f44f093 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,8 @@ - [ ] ๋‹น์ฒจ ๋‚ด์—ญ ์ถœ๋ ฅ - [ ] ์ˆ˜์ต๋ฅ  ์ถœ๋ ฅ +- [x] ๋กœ๋˜ ํด๋ž˜์Šค ์ž‘์„ฑ + ## ์‹คํ–‰ ์˜ˆ์‹œ ``` diff --git a/src/Lotto.js b/src/Lotto.js index cb0b1527e9..1c553f7678 100644 --- a/src/Lotto.js +++ b/src/Lotto.js @@ -1,5 +1,8 @@ +import { MissionUtils } from "@woowacourse/mission-utils"; + class Lotto { #numbers; + q2; constructor(numbers) { this.#validate(numbers); @@ -12,7 +15,46 @@ class Lotto { } } - // TODO: ์ถ”๊ฐ€ ๊ธฐ๋Šฅ ๊ตฌํ˜„ + //๋งž์ถ˜ ๊ฐœ์ˆ˜ ์นด์šดํŠธ + checkWinningCount(numbers, winningNumList) { + coincideNumCount = 0; + for (let i = 0; i < 6; i++) { + winningNumList.forEach((num) => { + if (Number(num) === numbers[i]) { + coincideNumCount++; + } + }); + } + return coincideNumCount; + } + // ๋ณด๋„ˆ์Šค ์ˆซ์ž ๋งž์ท„๋Š”์ง€ ์—ฌ๋ถ€ ํ™•์ธ + isBonusTrue(numbers, bonusNum) { + if (numbers.include(bonusNum)) { + return true; + } + return false; + } + + //๋งž์ถ˜ ์ˆซ์ž์— ๋”ฐ๋ฅธ ๋‹น์ฒจ ๊ธˆ์•ก ๊ณ„์‚ฐ + calcGetMoney(coincideNumCount, bonusTrue) { + if (coincideNumCount === 3) { + return 5000; + } + + if (coincideNumCount === 4) { + return 50000; + } + + if (coincideNumCount === 5) { + if (!bonusTrue) return 1500000; + return 30000000; + } + + if (coincideNumCount === 6) { + return 2000000000; + } + return 0; + } } export default Lotto; From 2321db32f576320bfe927fb5a44e534137f22824 Mon Sep 17 00:00:00 2001 From: nari Date: Wed, 8 Nov 2023 21:50:37 +0900 Subject: [PATCH 12/17] =?UTF-8?q?fix=20:=20=EC=98=A4=ED=83=80=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Lotto.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Lotto.js b/src/Lotto.js index 1c553f7678..618f9d1a4e 100644 --- a/src/Lotto.js +++ b/src/Lotto.js @@ -2,7 +2,6 @@ import { MissionUtils } from "@woowacourse/mission-utils"; class Lotto { #numbers; - q2; constructor(numbers) { this.#validate(numbers); From c34337c1c4d83f95db7f817849e14d5f24535c8f Mon Sep 17 00:00:00 2001 From: nari Date: Wed, 8 Nov 2023 22:50:12 +0900 Subject: [PATCH 13/17] =?UTF-8?q?feat=20:=20=EB=8B=B9=EC=B2=A8=20=EA=B0=9C?= =?UTF-8?q?=EC=88=98=20=EB=82=B4=EC=97=AD=20=EA=B3=84=EC=82=B0=20=EB=B0=8F?= =?UTF-8?q?=20=EC=B6=9C=EB=A0=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 5 ++--- src/App.js | 46 +++++++++++++++++++++++++++++++++++++++++++--- src/Lotto.js | 16 +++++++++------- 3 files changed, 54 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 392f44f093..dfe00b504f 100644 --- a/README.md +++ b/README.md @@ -13,13 +13,12 @@ - [x] ๊ตฌ๋งค ๊ธˆ์•ก์ด ์ˆซ์ž ์•„๋‹ ์‹œ ์˜ˆ์™ธ ์ฒ˜๋ฆฌ - [x] ๊ตฌ๋งค ๊ธˆ์•ก 1000์› ๋‹จ์œ„๊ฐ€ ์•„๋‹ ์‹œ ์˜ˆ์™ธ ์ฒ˜๋ฆฌ - [x] ๋‹น์ฒจ ๋ฒˆํ˜ธ ๋ฐ ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ ์ž…๋ ฅ ๋ฐ›๊ธฐ -- [x] ๋ฒˆํ˜ธ๊ฐ€ ์ˆซ์ž๊ฐ€ ์•„๋‹ ๊ฒฝ์šฐ ์˜ˆ์™ธ ์ฒ˜๋ฆฌ [๊ฒฐ๊ณผ ์ถœ๋ ฅ] - [x] ๋žœ๋ค ์ˆซ์ž๋กœ ๋กœ๋˜ ๋ฐœํ–‰ ๋ฐ ๊ฒฐ๊ณผ(์ˆ˜๋Ÿ‰ ๋ฐ ๋ฒˆํ˜ธ) ์ถœ๋ ฅ -- [ ] ๋‹น์ฒจ ๋‚ด์—ญ ์ถœ๋ ฅ -- [ ] ์ˆ˜์ต๋ฅ  ์ถœ๋ ฅ +- [x] ๋‹น์ฒจ ๋‚ด์—ญ ๊ณ„์‚ฐ ๋ฐ ์ถœ๋ ฅ +- [ ] ์ˆ˜์ต๋ฅ  ๊ณ„์‚ฐ ๋ฐ ์ถœ๋ ฅ - [x] ๋กœ๋˜ ํด๋ž˜์Šค ์ž‘์„ฑ diff --git a/src/App.js b/src/App.js index 872baa8657..4433f2bc39 100644 --- a/src/App.js +++ b/src/App.js @@ -1,4 +1,5 @@ import { MissionUtils } from "@woowacourse/mission-utils"; +import Lotto from "./Lotto.js"; class App { async play() { @@ -38,10 +39,49 @@ class App { MissionUtils.Console.print("๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."); const bonusNum = await MissionUtils.Console.readLineAsync(""); - //์ˆซ์ž ์•„๋‹ ์‹œ ์˜ˆ์™ธ ์ฒ˜๋ฆฌ - if (isNaN(winnigNum) === true || isNaN(bonusNum) === true) { - throw new Error("[ERROR] ์ˆซ์ž๋ฅผ ์ž…๋ ฅํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค."); + // ๋‹น์ฒจ ๊ฐœ์ˆ˜ ๋ฐ ๊ธˆ์•ก ๊ตฌํ•˜๊ธฐ + const totalWinningCount = [0, 0, 0, 0, 0, 0, 0, 0]; + + let totalWinningMoney = 0; + + for (let j = 0; j < boughtLottoCount; j++) { + console.log(totalLottoNumList[j]); + let lotto = new Lotto(totalLottoNumList[j]); + let tempWinningNum = lotto.checkWinningCount(winningNumList); + console.log(tempWinningNum); + let tempIsBonusTrue = lotto.isBonusTrue(bonusNum); + let tempGetMoney = lotto.calcGetMoney(tempWinningNum, tempIsBonusTrue); + totalWinningMoney += tempGetMoney; + if (tempWinningNum === 5) { + //5๊ฐœ + ๋ณด๋„ˆ์Šค ๋งž์ถ˜ ๊ฒฝ์šฐ 7๋ฒˆ ์ธ๋ฑ์Šค์— ์ €์žฅ + if (tempIsBonusTrue) { + totalWinningCount[7] += 1; + } + } + totalWinningCount[tempWinningNum] += 1; } + + //๋‹น์ฒจ ๊ฐœ์ˆ˜ ์ถœ๋ ฅ + const printTotalNumber = (totalWinningCount) => { + MissionUtils.Console.print(`๋‹น์ฒจ ํ†ต๊ณ„`); + MissionUtils.Console.print(`---`); + MissionUtils.Console.print( + `3๊ฐœ ์ผ์น˜ (5,000์›) - ${totalWinningCount[3]}๊ฐœ` + ); + MissionUtils.Console.print( + `4๊ฐœ ์ผ์น˜ (50,000์›) - ${totalWinningCount[4]}๊ฐœ` + ); + MissionUtils.Console.print( + `5๊ฐœ ์ผ์น˜ (1,500,000์›) - ${totalWinningCount[5]}๊ฐœ` + ); + MissionUtils.Console.print( + `5๊ฐœ ์ผ์น˜, ๋ณด๋„ˆ์Šค ๋ณผ ์ผ์น˜ (30,000,000์›) - ${totalWinningCount[7]}๊ฐœ` + ); + MissionUtils.Console.print( + `6๊ฐœ ์ผ์น˜ (2,000,000,000์›) - ${totalWinningCount[6]}๊ฐœ` + ); + }; + printTotalNumber(totalWinningCount); } } diff --git a/src/Lotto.js b/src/Lotto.js index 618f9d1a4e..66604f5a81 100644 --- a/src/Lotto.js +++ b/src/Lotto.js @@ -1,6 +1,6 @@ import { MissionUtils } from "@woowacourse/mission-utils"; -class Lotto { +export class Lotto { #numbers; constructor(numbers) { @@ -15,12 +15,14 @@ class Lotto { } //๋งž์ถ˜ ๊ฐœ์ˆ˜ ์นด์šดํŠธ - checkWinningCount(numbers, winningNumList) { - coincideNumCount = 0; - for (let i = 0; i < 6; i++) { + checkWinningCount(winningNumList) { + console.log("this.num"); + console.log(typeof this.#numbers[0]); + let coincideNumCount = 0; + for (var i = 0; i < 6; i++) { winningNumList.forEach((num) => { - if (Number(num) === numbers[i]) { - coincideNumCount++; + if (num === String(this.#numbers[i])) { + coincideNumCount += 1; } }); } @@ -28,7 +30,7 @@ class Lotto { } // ๋ณด๋„ˆ์Šค ์ˆซ์ž ๋งž์ท„๋Š”์ง€ ์—ฌ๋ถ€ ํ™•์ธ isBonusTrue(numbers, bonusNum) { - if (numbers.include(bonusNum)) { + if (numbers.includes(String(bonusNum))) { return true; } return false; From 52545c3ee39381cfd76e59b8822ab62f58b99b1e Mon Sep 17 00:00:00 2001 From: nari Date: Wed, 8 Nov 2023 22:50:37 +0900 Subject: [PATCH 14/17] =?UTF-8?q?feat=20:=20=EB=8B=B9=EC=B2=A8=20=EC=88=98?= =?UTF-8?q?=EC=9D=B5=EB=A5=A0=20=EA=B3=84=EC=82=B0=20=EB=B0=8F=20=EC=B6=9C?= =?UTF-8?q?=EB=A0=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- src/App.js | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index dfe00b504f..05447c1f57 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ - [x] ๋žœ๋ค ์ˆซ์ž๋กœ ๋กœ๋˜ ๋ฐœํ–‰ ๋ฐ ๊ฒฐ๊ณผ(์ˆ˜๋Ÿ‰ ๋ฐ ๋ฒˆํ˜ธ) ์ถœ๋ ฅ - [x] ๋‹น์ฒจ ๋‚ด์—ญ ๊ณ„์‚ฐ ๋ฐ ์ถœ๋ ฅ -- [ ] ์ˆ˜์ต๋ฅ  ๊ณ„์‚ฐ ๋ฐ ์ถœ๋ ฅ +- [x] ์ˆ˜์ต๋ฅ  ๊ณ„์‚ฐ ๋ฐ ์ถœ๋ ฅ - [x] ๋กœ๋˜ ํด๋ž˜์Šค ์ž‘์„ฑ diff --git a/src/App.js b/src/App.js index 4433f2bc39..3fa2688c21 100644 --- a/src/App.js +++ b/src/App.js @@ -82,6 +82,17 @@ class App { ); }; printTotalNumber(totalWinningCount); + + //๋‹น์ฒจ ์ˆ˜์ต๋ฅ  ๊ณ„์‚ฐ + const calcTotalProfitPercent = (totalWinningMoney, totalCost) => { + const totalProfitPercent = (totalWinningMoney / totalCost) * 100; + const temp = Number((Math.abs(totalProfitPercent) * 100).toPrecision(15)); + return (Math.round(temp) / 100) * Math.sign(totalProfitPercent); + }; + const totalProfit = calcTotalProfitPercent(totalWinningMoney, totalCost); + + //๋‹น์ฒจ ์ˆ˜์ต๋ฅ  ์ถœ๋ ฅ + MissionUtils.Console.print(`์ด ์ˆ˜์ต๋ฅ ์€ ${totalProfit}%์ž…๋‹ˆ๋‹ค.`); } } From 491d4b1cb8083b2ec532d75ca22de5c4c60a3bfa Mon Sep 17 00:00:00 2001 From: nari Date: Wed, 8 Nov 2023 23:26:13 +0900 Subject: [PATCH 15/17] =?UTF-8?q?refactor=20:=20=ED=95=A8=EC=88=98=20?= =?UTF-8?q?=EB=8B=A8=EC=9C=84=EB=A1=9C=20=EB=A6=AC=ED=8C=A9=ED=86=A0?= =?UTF-8?q?=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.js | 130 +++++++++++++++++++++++++++++++++-------------------- 1 file changed, 81 insertions(+), 49 deletions(-) diff --git a/src/App.js b/src/App.js index 3fa2688c21..17dd69a8f1 100644 --- a/src/App.js +++ b/src/App.js @@ -3,66 +3,86 @@ import Lotto from "./Lotto.js"; class App { async play() { - //๊ตฌ์ž… ๊ธˆ์•ก ์ž…๋ ฅ๋ฐ›๊ธฐ - MissionUtils.Console.print("๊ตฌ์ž…๊ธˆ์•ก์„ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."); - const totalCost = await MissionUtils.Console.readLineAsync(""); + //๊ตฌ์ž… ๊ธˆ์•ก ์ž…๋ ฅ๋ฐ›๋Š” ํ•จ์ˆ˜ + async function getUserCostInput() { + MissionUtils.Console.print("๊ตฌ์ž…๊ธˆ์•ก์„ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."); + const totalCost = await MissionUtils.Console.readLineAsync(""); - //๊ตฌ์ž… ๊ธˆ์•ก ์˜ˆ์™ธ ์ฒ˜๋ฆฌ - 1) ์ˆซ์ž๊ฐ€ ์•„๋‹ ๋•Œ - if (isNaN(totalCost) === true) { - throw new Error("[ERROR] ์ˆซ์ž๋ฅผ ์ž…๋ ฅํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค."); - } + //๊ตฌ์ž… ๊ธˆ์•ก ์˜ˆ์™ธ ์ฒ˜๋ฆฌ - 1) ์ˆซ์ž๊ฐ€ ์•„๋‹ ๋•Œ + if (isNaN(totalCost) === true) { + throw new Error("[ERROR] ์ˆซ์ž๋ฅผ ์ž…๋ ฅํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค."); + } - //๊ตฌ์ž… ๊ธˆ์•ก ์˜ˆ์™ธ ์ฒ˜๋ฆฌ - 2) 1000์› ๋‹จ์œ„๊ฐ€ ์•„๋‹ ๋•Œ - if (Number(totalCost) % 1000 !== 0) { - throw new Error("[ERROR] 1000์› ๋‹จ์œ„ ๊ธˆ์•ก์„ ์ž…๋ ฅํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค."); + //๊ตฌ์ž… ๊ธˆ์•ก ์˜ˆ์™ธ ์ฒ˜๋ฆฌ - 2) 1000์› ๋‹จ์œ„๊ฐ€ ์•„๋‹ ๋•Œ + if (Number(totalCost) % 1000 !== 0) { + throw new Error("[ERROR] 1000์› ๋‹จ์œ„ ๊ธˆ์•ก์„ ์ž…๋ ฅํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค."); + } + return totalCost; } - // ๊ตฌ๋งค ๊ฐœ์ˆ˜ ๋งŒํผ ์ถ”์ฒจ ๋ฒˆํ˜ธ ์ƒ์„ฑ ๋ฐ ์ถœ๋ ฅ - const boughtLottoCount = totalCost / 1000; - const totalLottoNumList = []; - MissionUtils.Console.print(`${boughtLottoCount}๊ฐœ๋ฅผ ๊ตฌ๋งคํ–ˆ์Šต๋‹ˆ๋‹ค.`); - for (let i = 0; i < boughtLottoCount; i++) { - const nowLottoNumList = MissionUtils.Random.pickUniqueNumbersInRange( - 1, - 45, - 6 - ); - MissionUtils.Console.print(nowLottoNumList); - totalLottoNumList.push(nowLottoNumList); + // ๊ตฌ๋งค ๊ฐœ์ˆ˜ ๋งŒํผ ์ถ”์ฒจ ๋ฒˆํ˜ธ ์ƒ์„ฑ ํ•จ์ˆ˜ + function makeNewLotto(boughtLottoCount) { + const totalLottoNumList = []; + for (let i = 0; i < boughtLottoCount; i++) { + const nowLottoNumList = MissionUtils.Random.pickUniqueNumbersInRange( + 1, + 45, + 6 + ); + totalLottoNumList.push(nowLottoNumList); + } + return totalLottoNumList; } - // ๋‹น์ฒจ ๋ฒˆํ˜ธ ๋ฐ ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ ์ž…๋ ฅ ๋ฐ›๊ธฐ - MissionUtils.Console.print("๋‹น์ฒจ ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."); - const winnigNum = await MissionUtils.Console.readLineAsync(""); - const winningNumList = winnigNum.split(","); + //๋กœ๋˜ ์ถœ๋ ฅ ํ•จ์ˆ˜ + function printNewLotto(boughtLottoCount, totalLottoNumList) { + MissionUtils.Console.print(`${boughtLottoCount}๊ฐœ๋ฅผ ๊ตฌ๋งคํ–ˆ์Šต๋‹ˆ๋‹ค.`); + totalLottoNumList.forEach((lotto) => MissionUtils.Console.print(lotto)); + } - MissionUtils.Console.print("๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."); - const bonusNum = await MissionUtils.Console.readLineAsync(""); + // ๋‹น์ฒจ ๋ฒˆํ˜ธ ์ž…๋ ฅ ๋ฐ›๋Š” ํ•จ์ˆ˜ + async function getUserWinningNumInput() { + MissionUtils.Console.print("๋‹น์ฒจ ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."); + const winnigNum = await MissionUtils.Console.readLineAsync(""); + const winningNumList = winnigNum.split(","); + return winningNumList; + } - // ๋‹น์ฒจ ๊ฐœ์ˆ˜ ๋ฐ ๊ธˆ์•ก ๊ตฌํ•˜๊ธฐ - const totalWinningCount = [0, 0, 0, 0, 0, 0, 0, 0]; + // ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ ์ž…๋ ฅ ๋ฐ›๋Š” ํ•จ์ˆ˜ + async function getUserBonusNumInput() { + MissionUtils.Console.print("๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."); + const bonusNum = await MissionUtils.Console.readLineAsync(""); + return bonusNum; + } - let totalWinningMoney = 0; + // ๋‹น์ฒจ ๊ฐœ์ˆ˜ ๋ฐ ๊ธˆ์•ก ๊ตฌํ•˜๋Š” ํ•จ์ˆ˜ + function calcTotalWinningCount( + boughtLottoCount, + totalLottoNumList, + winningNumList + ) { + const totalWinningCount = [0, 0, 0, 0, 0, 0, 0, 0]; + let totalWinningMoney = 0; - for (let j = 0; j < boughtLottoCount; j++) { - console.log(totalLottoNumList[j]); - let lotto = new Lotto(totalLottoNumList[j]); - let tempWinningNum = lotto.checkWinningCount(winningNumList); - console.log(tempWinningNum); - let tempIsBonusTrue = lotto.isBonusTrue(bonusNum); - let tempGetMoney = lotto.calcGetMoney(tempWinningNum, tempIsBonusTrue); - totalWinningMoney += tempGetMoney; - if (tempWinningNum === 5) { - //5๊ฐœ + ๋ณด๋„ˆ์Šค ๋งž์ถ˜ ๊ฒฝ์šฐ 7๋ฒˆ ์ธ๋ฑ์Šค์— ์ €์žฅ - if (tempIsBonusTrue) { - totalWinningCount[7] += 1; + for (let j = 0; j < boughtLottoCount; j++) { + let lotto = new Lotto(totalLottoNumList[j]); + let tempWinningNum = lotto.checkWinningCount(winningNumList); + let tempIsBonusTrue = lotto.isBonusTrue(bonusNum); + let tempGetMoney = lotto.calcGetMoney(tempWinningNum, tempIsBonusTrue); + totalWinningMoney += tempGetMoney; + if (tempWinningNum === 5) { + //5๊ฐœ + ๋ณด๋„ˆ์Šค ๋งž์ถ˜ ๊ฒฝ์šฐ 7๋ฒˆ ์ธ๋ฑ์Šค์— ์ €์žฅ + if (tempIsBonusTrue) { + totalWinningCount[7] += 1; + } } + totalWinningCount[tempWinningNum] += 1; } - totalWinningCount[tempWinningNum] += 1; + return [totalWinningCount, totalWinningMoney]; } //๋‹น์ฒจ ๊ฐœ์ˆ˜ ์ถœ๋ ฅ - const printTotalNumber = (totalWinningCount) => { + function printTotalNumber(totalWinningCount) { MissionUtils.Console.print(`๋‹น์ฒจ ํ†ต๊ณ„`); MissionUtils.Console.print(`---`); MissionUtils.Console.print( @@ -80,15 +100,27 @@ class App { MissionUtils.Console.print( `6๊ฐœ ์ผ์น˜ (2,000,000,000์›) - ${totalWinningCount[6]}๊ฐœ` ); - }; - printTotalNumber(totalWinningCount); + } //๋‹น์ฒจ ์ˆ˜์ต๋ฅ  ๊ณ„์‚ฐ - const calcTotalProfitPercent = (totalWinningMoney, totalCost) => { + function calcTotalProfitPercent(totalWinningMoney, totalCost) { const totalProfitPercent = (totalWinningMoney / totalCost) * 100; const temp = Number((Math.abs(totalProfitPercent) * 100).toPrecision(15)); return (Math.round(temp) / 100) * Math.sign(totalProfitPercent); - }; + } + + const totalCost = await getUserCostInput(); + const boughtLottoCount = totalCost / 1000; + const totalLottoNumList = makeNewLotto(boughtLottoCount); + printNewLotto(boughtLottoCount, totalLottoNumList); + const winningNumList = await getUserWinningNumInput(); + const bonusNum = await getUserBonusNumInput(); + const [totalWinningCount, totalWinningMoney] = calcTotalWinningCount( + boughtLottoCount, + totalLottoNumList, + winningNumList + ); + printTotalNumber(totalWinningCount); const totalProfit = calcTotalProfitPercent(totalWinningMoney, totalCost); //๋‹น์ฒจ ์ˆ˜์ต๋ฅ  ์ถœ๋ ฅ From 921cebc294fc2d458908557b234b93d93029bd94 Mon Sep 17 00:00:00 2001 From: nari Date: Wed, 8 Nov 2023 23:26:44 +0900 Subject: [PATCH 16/17] =?UTF-8?q?fix=20:=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20=EC=B6=9C=EB=A0=A5=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Lotto.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Lotto.js b/src/Lotto.js index 66604f5a81..fb172bb848 100644 --- a/src/Lotto.js +++ b/src/Lotto.js @@ -16,8 +16,6 @@ export class Lotto { //๋งž์ถ˜ ๊ฐœ์ˆ˜ ์นด์šดํŠธ checkWinningCount(winningNumList) { - console.log("this.num"); - console.log(typeof this.#numbers[0]); let coincideNumCount = 0; for (var i = 0; i < 6; i++) { winningNumList.forEach((num) => { @@ -28,6 +26,7 @@ export class Lotto { } return coincideNumCount; } + // ๋ณด๋„ˆ์Šค ์ˆซ์ž ๋งž์ท„๋Š”์ง€ ์—ฌ๋ถ€ ํ™•์ธ isBonusTrue(numbers, bonusNum) { if (numbers.includes(String(bonusNum))) { From ebbc8a7481175165feb29083f850e7a64e3de7f0 Mon Sep 17 00:00:00 2001 From: nari Date: Wed, 8 Nov 2023 23:57:02 +0900 Subject: [PATCH 17/17] =?UTF-8?q?refactor=20:=20test=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __tests__/ApplicationTest.js | 7 +++---- __tests__/LottoTest.js | 5 +++++ src/App.js | 17 ++++++++++++++--- src/Lotto.js | 8 ++++++++ 4 files changed, 30 insertions(+), 7 deletions(-) diff --git a/__tests__/ApplicationTest.js b/__tests__/ApplicationTest.js index 227bd03864..c82e1f5f34 100644 --- a/__tests__/ApplicationTest.js +++ b/__tests__/ApplicationTest.js @@ -28,7 +28,7 @@ const runException = async (input) => { // given const logSpy = getLogSpy(); - const RANDOM_NUMBERS_TO_END = [1,2,3,4,5,6]; + const RANDOM_NUMBERS_TO_END = [1, 2, 3, 4, 5, 6]; const INPUT_NUMBERS_TO_END = ["1000", "1,2,3,4,5,6", "7"]; mockRandoms([RANDOM_NUMBERS_TO_END]); @@ -40,12 +40,12 @@ const runException = async (input) => { // then expect(logSpy).toHaveBeenCalledWith(expect.stringContaining("[ERROR]")); -} +}; describe("๋กœ๋˜ ํ…Œ์ŠคํŠธ", () => { beforeEach(() => { jest.restoreAllMocks(); - }) + }); test("๊ธฐ๋Šฅ ํ…Œ์ŠคํŠธ", async () => { // given @@ -95,4 +95,3 @@ describe("๋กœ๋˜ ํ…Œ์ŠคํŠธ", () => { await runException("1000j"); }); }); - diff --git a/__tests__/LottoTest.js b/__tests__/LottoTest.js index 97bd457659..c8178db14c 100644 --- a/__tests__/LottoTest.js +++ b/__tests__/LottoTest.js @@ -15,4 +15,9 @@ describe("๋กœ๋˜ ํด๋ž˜์Šค ํ…Œ์ŠคํŠธ", () => { }); // ์•„๋ž˜์— ์ถ”๊ฐ€ ํ…Œ์ŠคํŠธ ์ž‘์„ฑ ๊ฐ€๋Šฅ + // test("๋กœ๋˜๊ฐ€ 3๊ฐœ ์ผ์น˜ํ•˜๋ฉด checkWinningCount๊ฐ€ 3์„ ๋ฐ˜ํ™˜", () => { + // expect(() => { + // new Lotto([1, 2, 3, 4, 5, 6]).checkWinningCount([1, 2, 3, 10, 11, 12]); + // }).toBe(3); + // }); }); diff --git a/src/App.js b/src/App.js index 17dd69a8f1..c83f1a44c9 100644 --- a/src/App.js +++ b/src/App.js @@ -5,11 +5,18 @@ class App { async play() { //๊ตฌ์ž… ๊ธˆ์•ก ์ž…๋ ฅ๋ฐ›๋Š” ํ•จ์ˆ˜ async function getUserCostInput() { + const isNumber = (pVal) => { + if (isEmpty(pVal)) { + return false; + } + return !isNaN(pVal); + }; MissionUtils.Console.print("๊ตฌ์ž…๊ธˆ์•ก์„ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."); const totalCost = await MissionUtils.Console.readLineAsync(""); - //๊ตฌ์ž… ๊ธˆ์•ก ์˜ˆ์™ธ ์ฒ˜๋ฆฌ - 1) ์ˆซ์ž๊ฐ€ ์•„๋‹ ๋•Œ - if (isNaN(totalCost) === true) { + // ๊ตฌ์ž… ๊ธˆ์•ก ์˜ˆ์™ธ ์ฒ˜๋ฆฌ - 1) ์ˆซ์ž๊ฐ€ ์•„๋‹ ๋•Œ + + if (!Number(totalCost)) { throw new Error("[ERROR] ์ˆซ์ž๋ฅผ ์ž…๋ ฅํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค."); } @@ -37,7 +44,9 @@ class App { //๋กœ๋˜ ์ถœ๋ ฅ ํ•จ์ˆ˜ function printNewLotto(boughtLottoCount, totalLottoNumList) { MissionUtils.Console.print(`${boughtLottoCount}๊ฐœ๋ฅผ ๊ตฌ๋งคํ–ˆ์Šต๋‹ˆ๋‹ค.`); - totalLottoNumList.forEach((lotto) => MissionUtils.Console.print(lotto)); + totalLottoNumList.forEach((lotto) => + MissionUtils.Console.print(`[${lotto.join(", ")}]`) + ); } // ๋‹น์ฒจ ๋ฒˆํ˜ธ ์ž…๋ ฅ ๋ฐ›๋Š” ํ•จ์ˆ˜ @@ -45,6 +54,7 @@ class App { MissionUtils.Console.print("๋‹น์ฒจ ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."); const winnigNum = await MissionUtils.Console.readLineAsync(""); const winningNumList = winnigNum.split(","); + return winningNumList; } @@ -66,6 +76,7 @@ class App { for (let j = 0; j < boughtLottoCount; j++) { let lotto = new Lotto(totalLottoNumList[j]); + let tempWinningNum = lotto.checkWinningCount(winningNumList); let tempIsBonusTrue = lotto.isBonusTrue(bonusNum); let tempGetMoney = lotto.calcGetMoney(tempWinningNum, tempIsBonusTrue); diff --git a/src/Lotto.js b/src/Lotto.js index fb172bb848..78c8c79a65 100644 --- a/src/Lotto.js +++ b/src/Lotto.js @@ -5,6 +5,7 @@ export class Lotto { constructor(numbers) { this.#validate(numbers); + this.#numbers = numbers; } @@ -12,6 +13,13 @@ export class Lotto { if (numbers.length !== 6) { throw new Error("[ERROR] ๋กœ๋˜ ๋ฒˆํ˜ธ๋Š” 6๊ฐœ์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค."); } + for (let n = 0; n < numbers.length; n++) { + for (let m = n + 1; m < numbers.length; m++) { + if (numbers[m] === numbers[n]) { + throw new Error("[ERROR] ์ค‘๋ณต๋œ ์ˆซ์ž๋ฅผ ์ž…๋ ฅํ•˜๋ฉด ์•ˆ๋ฉ๋‹ˆ๋‹ค."); + } + } + } } //๋งž์ถ˜ ๊ฐœ์ˆ˜ ์นด์šดํŠธ