From 3ae79afcfd4aad011e961ecf116b8a7a3c7f81ce Mon Sep 17 00:00:00 2001 From: hyeonjin6530 Date: Mon, 4 Nov 2024 11:47:17 +0900 Subject: [PATCH 01/10] =?UTF-8?q?docs:=20README.md=EC=97=90=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84=ED=95=A0=20=EA=B8=B0=EB=8A=A5=20=EB=AA=A9=EB=A1=9D=20?= =?UTF-8?q?=EC=A0=95=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 114 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 15bb106b5..460e51a5a 100644 --- a/README.md +++ b/README.md @@ -1 +1,114 @@ -# javascript-lotto-precourse +# ๋กœ๋˜ (javascript-lotto-precourse) + +## ๐Ÿฅ ๊ธฐ๋Šฅ ์š”๊ตฌ ์‚ฌํ•ญ +์ดˆ๊ฐ„๋‹จ ์ž๋™์ฐจ ๊ฒฝ์ฃผ ๊ฒŒ์ž„์„ ๊ตฌํ˜„ํ•œ๋‹ค. + +- [x] ๋กœ๋˜ ๋ฒˆํ˜ธ์˜ ์ˆซ์ž ๋ฒ”์œ„๋Š” 1~45๊นŒ์ง€์ด๋‹ค. + +- [x] 1๊ฐœ์˜ ๋กœ๋˜๋ฅผ ๋ฐœํ–‰ํ•  ๋•Œ ์ค‘๋ณต๋˜์ง€ ์•Š๋Š” 6๊ฐœ์˜ ์ˆซ์ž๋ฅผ ๋ฝ‘๋Š”๋‹ค. + +- [x] ๋‹น์ฒจ ๋ฒˆํ˜ธ ์ถ”์ฒจ ์‹œ ์ค‘๋ณต๋˜์ง€ ์•Š๋Š” ์ˆซ์ž 6๊ฐœ์™€ ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ 1๊ฐœ๋ฅผ ๋ฝ‘๋Š”๋‹ค. + +- [x] ๋‹น์ฒจ์€ 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์› + +- [x] ๋กœ๋˜ ๊ตฌ์ž… ๊ธˆ์•ก์„ ์ž…๋ ฅํ•˜๋ฉด ๊ตฌ์ž… ๊ธˆ์•ก์— ํ•ด๋‹นํ•˜๋Š” ๋งŒํผ ๋กœ๋˜๋ฅผ ๋ฐœํ–‰ํ•ด์•ผ ํ•œ๋‹ค. + +- [x] ๋กœ๋˜ 1์žฅ์˜ ๊ฐ€๊ฒฉ์€ 1,000์›์ด๋‹ค. + +- [x] ๋‹น์ฒจ ๋ฒˆํ˜ธ์™€ ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅ๋ฐ›๋Š”๋‹ค. + +- [x] ์‚ฌ์šฉ์ž๊ฐ€ ๊ตฌ๋งคํ•œ ๋กœ๋˜ ๋ฒˆํ˜ธ์™€ ๋‹น์ฒจ ๋ฒˆํ˜ธ๋ฅผ ๋น„๊ตํ•˜์—ฌ ๋‹น์ฒจ ๋‚ด์—ญ ๋ฐ ์ˆ˜์ต๋ฅ ์„ ์ถœ๋ ฅํ•˜๊ณ  ๋กœ๋˜ ๊ฒŒ์ž„์„ ์ข…๋ฃŒํ•œ๋‹ค. + +- ์‚ฌ์šฉ์ž๊ฐ€ ์ž˜๋ชป๋œ ๊ฐ’์„ ์ž…๋ ฅํ•  ๊ฒฝ์šฐ "[ERROR]"๋กœ ์‹œ์ž‘ํ•˜๋Š” ๋ฉ”์‹œ์ง€์™€ ํ•จ๊ป˜ Error๋ฅผ ๋ฐœ์ƒ์‹œํ‚ค๊ณ  ํ•ด๋‹น ๋ฉ”์‹œ์ง€๋ฅผ ์ถœ๋ ฅํ•œ ๋‹ค์Œ ํ•ด๋‹น ์ง€์ ๋ถ€ํ„ฐ ๋‹ค์‹œ ์ž…๋ ฅ์„ ๋ฐ›๋Š”๋‹ค. + - [x] ์ˆซ์ž ๋ฒ”์œ„๊ฐ€ 1~45๋ฅผ ๋„˜์–ด๊ฐ€๊ฒŒ ์ž…๋ ฅํ•œ ๊ฒฝ์šฐ + - [x] ์ˆซ์ž๊ฐ€ ์•„๋‹Œ ๋ฌธ์ž๋ฅผ ์ž…๋ ฅํ•œ ๊ฒฝ์šฐ + - [x] ๊ตฌ์ž… ๊ธˆ์•ก์ด 1,000์›์œผ๋กœ ๋‚˜๋ˆ„์–ด ๋–จ์–ด์ง€์ง€ ์•Š๋Š” ๊ฒฝ์šฐ + - [x] ์ค‘๋ณต๋œ ์ˆซ์ž๊ฐ€ ์žˆ๋Š” ๊ฒฝ์šฐ + - [x] ๋กœ๋˜ ๋ฒˆํ˜ธ๋ฅผ 6๊ฐœ ์ด์ƒ ์ž…๋ ฅํ•œ ๊ฒฝ์šฐ + + +## ๐Ÿฅ ์ž…์ถœ๋ ฅ ์š”๊ตฌ ์‚ฌํ•ญ +- ์ž…๋ ฅ + - ๋กœ๋˜ ๊ตฌ์ž… ๊ธˆ์•ก์„ ์ž…๋ ฅ ๋ฐ›๋Š”๋‹ค. ๊ตฌ์ž… ๊ธˆ์•ก์€ 1,000์› ๋‹จ์œ„๋กœ ์ž…๋ ฅ ๋ฐ›์œผ๋ฉฐ 1,000์›์œผ๋กœ ๋‚˜๋ˆ„์–ด ๋–จ์–ด์ง€์ง€ ์•Š๋Š” ๊ฒฝ์šฐ ์˜ˆ์™ธ ์ฒ˜๋ฆฌํ•œ๋‹ค. + ```jsx + 14000 + ``` + + - ๋‹น์ฒจ ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅ ๋ฐ›๋Š”๋‹ค. ๋ฒˆํ˜ธ๋Š” ์‰ผํ‘œ(,)๋ฅผ ๊ธฐ์ค€์œผ๋กœ ๊ตฌ๋ถ„ํ•œ๋‹ค. + ```jsx + 1,2,3,4,5,6 + ``` + + - ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅ ๋ฐ›๋Š”๋‹ค. + ```jsx + 7 + ``` + +- ์ถœ๋ ฅ + - ๋ฐœํ–‰ํ•œ ๋กœ๋˜ ์ˆ˜๋Ÿ‰ ๋ฐ ๋ฒˆํ˜ธ๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค. ๋กœ๋˜ ๋ฒˆํ˜ธ๋Š” ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌํ•˜์—ฌ ๋ณด์—ฌ์ค€๋‹ค. + ```jsx + 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] + ``` + + - ๋‹น์ฒจ ๋‚ด์—ญ์„ ์ถœ๋ ฅํ•œ๋‹ค. + ```jsx + 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%) + ```jsx + ์ด ์ˆ˜์ต๋ฅ ์€ 62.5%์ž…๋‹ˆ๋‹ค. + ``` + + - ์ˆ˜์ต๋ฅ ์€ ์†Œ์ˆ˜์  ๋‘˜์งธ ์ž๋ฆฌ์—์„œ ๋ฐ˜์˜ฌ๋ฆผํ•œ๋‹ค. (ex. 100.0%, 51.5%, 1,000,000.0%) + ```jsx + [ERROR] ๋กœ๋˜ ๋ฒˆํ˜ธ๋Š” 1๋ถ€ํ„ฐ 45 ์‚ฌ์ด์˜ ์ˆซ์ž์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค. + ``` + +- ์‹คํ–‰ ๊ฒฐ๊ณผ ์˜ˆ์‹œ + ```jsx + ๊ตฌ์ž…๊ธˆ์•ก์„ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”. + 8000 + + 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] + + ๋‹น์ฒจ ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”. + 1,2,3,4,5,6 + + ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”. + 7 + + ๋‹น์ฒจ ํ†ต๊ณ„ + --- + 3๊ฐœ ์ผ์น˜ (5,000์›) - 1๊ฐœ + 4๊ฐœ ์ผ์น˜ (50,000์›) - 0๊ฐœ + 5๊ฐœ ์ผ์น˜ (1,500,000์›) - 0๊ฐœ + 5๊ฐœ ์ผ์น˜, ๋ณด๋„ˆ์Šค ๋ณผ ์ผ์น˜ (30,000,000์›) - 0๊ฐœ + 6๊ฐœ ์ผ์น˜ (2,000,000,000์›) - 0๊ฐœ + ์ด ์ˆ˜์ต๋ฅ ์€ 62.5%์ž…๋‹ˆ๋‹ค. + ``` \ No newline at end of file From 990cf062506dc756547ec1433764a03d727d73e9 Mon Sep 17 00:00:00 2001 From: hyeonjin6530 Date: Mon, 4 Nov 2024 13:35:21 +0900 Subject: [PATCH 02/10] =?UTF-8?q?docs:=20README.md=20=EC=98=A4=ED=83=80=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 --- README.md | 80 +++++++++++++++++++++++++++---------------------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index 460e51a5a..04896f923 100644 --- a/README.md +++ b/README.md @@ -3,33 +3,33 @@ ## ๐Ÿฅ ๊ธฐ๋Šฅ ์š”๊ตฌ ์‚ฌํ•ญ ์ดˆ๊ฐ„๋‹จ ์ž๋™์ฐจ ๊ฒฝ์ฃผ ๊ฒŒ์ž„์„ ๊ตฌํ˜„ํ•œ๋‹ค. -- [x] ๋กœ๋˜ ๋ฒˆํ˜ธ์˜ ์ˆซ์ž ๋ฒ”์œ„๋Š” 1~45๊นŒ์ง€์ด๋‹ค. +- [ ] ๋กœ๋˜ ๋ฒˆํ˜ธ์˜ ์ˆซ์ž ๋ฒ”์œ„๋Š” 1~45๊นŒ์ง€์ด๋‹ค. -- [x] 1๊ฐœ์˜ ๋กœ๋˜๋ฅผ ๋ฐœํ–‰ํ•  ๋•Œ ์ค‘๋ณต๋˜์ง€ ์•Š๋Š” 6๊ฐœ์˜ ์ˆซ์ž๋ฅผ ๋ฝ‘๋Š”๋‹ค. +- [ ] 1๊ฐœ์˜ ๋กœ๋˜๋ฅผ ๋ฐœํ–‰ํ•  ๋•Œ ์ค‘๋ณต๋˜์ง€ ์•Š๋Š” 6๊ฐœ์˜ ์ˆซ์ž๋ฅผ ๋ฝ‘๋Š”๋‹ค. -- [x] ๋‹น์ฒจ ๋ฒˆํ˜ธ ์ถ”์ฒจ ์‹œ ์ค‘๋ณต๋˜์ง€ ์•Š๋Š” ์ˆซ์ž 6๊ฐœ์™€ ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ 1๊ฐœ๋ฅผ ๋ฝ‘๋Š”๋‹ค. +- [ ] ๋‹น์ฒจ ๋ฒˆํ˜ธ ์ถ”์ฒจ ์‹œ ์ค‘๋ณต๋˜์ง€ ์•Š๋Š” ์ˆซ์ž 6๊ฐœ์™€ ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ 1๊ฐœ๋ฅผ ๋ฝ‘๋Š”๋‹ค. -- [x] ๋‹น์ฒจ์€ 1๋“ฑ๋ถ€ํ„ฐ 5๋“ฑ๊นŒ์ง€ ์žˆ๋‹ค. ๋‹น์ฒจ ๊ธฐ์ค€๊ณผ ๊ธˆ์•ก์€ ์•„๋ž˜์™€ ๊ฐ™๋‹ค. +- [ ] ๋‹น์ฒจ์€ 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์› -- [x] ๋กœ๋˜ ๊ตฌ์ž… ๊ธˆ์•ก์„ ์ž…๋ ฅํ•˜๋ฉด ๊ตฌ์ž… ๊ธˆ์•ก์— ํ•ด๋‹นํ•˜๋Š” ๋งŒํผ ๋กœ๋˜๋ฅผ ๋ฐœํ–‰ํ•ด์•ผ ํ•œ๋‹ค. +- [ ] ๋กœ๋˜ ๊ตฌ์ž… ๊ธˆ์•ก์„ ์ž…๋ ฅํ•˜๋ฉด ๊ตฌ์ž… ๊ธˆ์•ก์— ํ•ด๋‹นํ•˜๋Š” ๋งŒํผ ๋กœ๋˜๋ฅผ ๋ฐœํ–‰ํ•ด์•ผ ํ•œ๋‹ค. -- [x] ๋กœ๋˜ 1์žฅ์˜ ๊ฐ€๊ฒฉ์€ 1,000์›์ด๋‹ค. +- [ ] ๋กœ๋˜ 1์žฅ์˜ ๊ฐ€๊ฒฉ์€ 1,000์›์ด๋‹ค. -- [x] ๋‹น์ฒจ ๋ฒˆํ˜ธ์™€ ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅ๋ฐ›๋Š”๋‹ค. +- [ ] ๋‹น์ฒจ ๋ฒˆํ˜ธ์™€ ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅ๋ฐ›๋Š”๋‹ค. -- [x] ์‚ฌ์šฉ์ž๊ฐ€ ๊ตฌ๋งคํ•œ ๋กœ๋˜ ๋ฒˆํ˜ธ์™€ ๋‹น์ฒจ ๋ฒˆํ˜ธ๋ฅผ ๋น„๊ตํ•˜์—ฌ ๋‹น์ฒจ ๋‚ด์—ญ ๋ฐ ์ˆ˜์ต๋ฅ ์„ ์ถœ๋ ฅํ•˜๊ณ  ๋กœ๋˜ ๊ฒŒ์ž„์„ ์ข…๋ฃŒํ•œ๋‹ค. +- [ ] ์‚ฌ์šฉ์ž๊ฐ€ ๊ตฌ๋งคํ•œ ๋กœ๋˜ ๋ฒˆํ˜ธ์™€ ๋‹น์ฒจ ๋ฒˆํ˜ธ๋ฅผ ๋น„๊ตํ•˜์—ฌ ๋‹น์ฒจ ๋‚ด์—ญ ๋ฐ ์ˆ˜์ต๋ฅ ์„ ์ถœ๋ ฅํ•˜๊ณ  ๋กœ๋˜ ๊ฒŒ์ž„์„ ์ข…๋ฃŒํ•œ๋‹ค. - ์‚ฌ์šฉ์ž๊ฐ€ ์ž˜๋ชป๋œ ๊ฐ’์„ ์ž…๋ ฅํ•  ๊ฒฝ์šฐ "[ERROR]"๋กœ ์‹œ์ž‘ํ•˜๋Š” ๋ฉ”์‹œ์ง€์™€ ํ•จ๊ป˜ Error๋ฅผ ๋ฐœ์ƒ์‹œํ‚ค๊ณ  ํ•ด๋‹น ๋ฉ”์‹œ์ง€๋ฅผ ์ถœ๋ ฅํ•œ ๋‹ค์Œ ํ•ด๋‹น ์ง€์ ๋ถ€ํ„ฐ ๋‹ค์‹œ ์ž…๋ ฅ์„ ๋ฐ›๋Š”๋‹ค. - - [x] ์ˆซ์ž ๋ฒ”์œ„๊ฐ€ 1~45๋ฅผ ๋„˜์–ด๊ฐ€๊ฒŒ ์ž…๋ ฅํ•œ ๊ฒฝ์šฐ - - [x] ์ˆซ์ž๊ฐ€ ์•„๋‹Œ ๋ฌธ์ž๋ฅผ ์ž…๋ ฅํ•œ ๊ฒฝ์šฐ - - [x] ๊ตฌ์ž… ๊ธˆ์•ก์ด 1,000์›์œผ๋กœ ๋‚˜๋ˆ„์–ด ๋–จ์–ด์ง€์ง€ ์•Š๋Š” ๊ฒฝ์šฐ - - [x] ์ค‘๋ณต๋œ ์ˆซ์ž๊ฐ€ ์žˆ๋Š” ๊ฒฝ์šฐ - - [x] ๋กœ๋˜ ๋ฒˆํ˜ธ๋ฅผ 6๊ฐœ ์ด์ƒ ์ž…๋ ฅํ•œ ๊ฒฝ์šฐ + - [ ] ์ˆซ์ž ๋ฒ”์œ„๊ฐ€ 1~45๋ฅผ ๋„˜์–ด๊ฐ€๊ฒŒ ์ž…๋ ฅํ•œ ๊ฒฝ์šฐ + - [ ] ์ˆซ์ž๊ฐ€ ์•„๋‹Œ ๋ฌธ์ž๋ฅผ ์ž…๋ ฅํ•œ ๊ฒฝ์šฐ + - [ ] ๊ตฌ์ž… ๊ธˆ์•ก์ด 1,000์›์œผ๋กœ ๋‚˜๋ˆ„์–ด ๋–จ์–ด์ง€์ง€ ์•Š๋Š” ๊ฒฝ์šฐ + - [ ] ์ค‘๋ณต๋œ ์ˆซ์ž๊ฐ€ ์žˆ๋Š” ๊ฒฝ์šฐ + - [ ] ๋กœ๋˜ ๋ฒˆํ˜ธ๋ฅผ 6๊ฐœ ์ด์ƒ ์ž…๋ ฅํ•œ ๊ฒฝ์šฐ ## ๐Ÿฅ ์ž…์ถœ๋ ฅ ์š”๊ตฌ ์‚ฌํ•ญ @@ -84,31 +84,31 @@ - ์‹คํ–‰ ๊ฒฐ๊ณผ ์˜ˆ์‹œ ```jsx - ๊ตฌ์ž…๊ธˆ์•ก์„ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”. - 8000 - - 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] - - ๋‹น์ฒจ ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”. - 1,2,3,4,5,6 - - ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”. - 7 - - ๋‹น์ฒจ ํ†ต๊ณ„ - --- - 3๊ฐœ ์ผ์น˜ (5,000์›) - 1๊ฐœ - 4๊ฐœ ์ผ์น˜ (50,000์›) - 0๊ฐœ - 5๊ฐœ ์ผ์น˜ (1,500,000์›) - 0๊ฐœ - 5๊ฐœ ์ผ์น˜, ๋ณด๋„ˆ์Šค ๋ณผ ์ผ์น˜ (30,000,000์›) - 0๊ฐœ - 6๊ฐœ ์ผ์น˜ (2,000,000,000์›) - 0๊ฐœ - ์ด ์ˆ˜์ต๋ฅ ์€ 62.5%์ž…๋‹ˆ๋‹ค. + ๊ตฌ์ž…๊ธˆ์•ก์„ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”. + 8000 + + 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] + + ๋‹น์ฒจ ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”. + 1,2,3,4,5,6 + + ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”. + 7 + + ๋‹น์ฒจ ํ†ต๊ณ„ + --- + 3๊ฐœ ์ผ์น˜ (5,000์›) - 1๊ฐœ + 4๊ฐœ ์ผ์น˜ (50,000์›) - 0๊ฐœ + 5๊ฐœ ์ผ์น˜ (1,500,000์›) - 0๊ฐœ + 5๊ฐœ ์ผ์น˜, ๋ณด๋„ˆ์Šค ๋ณผ ์ผ์น˜ (30,000,000์›) - 0๊ฐœ + 6๊ฐœ ์ผ์น˜ (2,000,000,000์›) - 0๊ฐœ + ์ด ์ˆ˜์ต๋ฅ ์€ 62.5%์ž…๋‹ˆ๋‹ค. ``` \ No newline at end of file From 4cb2f6311a85c9e68244b862048cb1307d517476 Mon Sep 17 00:00:00 2001 From: hyeonjin6530 Date: Mon, 4 Nov 2024 14:00:36 +0900 Subject: [PATCH 03/10] =?UTF-8?q?feat:=20=EC=BD=98=EC=86=94=20=EC=9E=85?= =?UTF-8?q?=EB=A0=A5=20=EB=B0=8F=20=EC=B6=9C=EB=A0=A5=EC=9D=84=20=EC=9C=A0?= =?UTF-8?q?=ED=8B=B8=EB=A6=AC=ED=8B=B0=20=ED=95=A8=EC=88=98=EB=A1=9C=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- src/utils/ConsoleUtil.js | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 src/utils/ConsoleUtil.js diff --git a/README.md b/README.md index 04896f923..9f3e2d799 100644 --- a/README.md +++ b/README.md @@ -111,4 +111,4 @@ 5๊ฐœ ์ผ์น˜, ๋ณด๋„ˆ์Šค ๋ณผ ์ผ์น˜ (30,000,000์›) - 0๊ฐœ 6๊ฐœ ์ผ์น˜ (2,000,000,000์›) - 0๊ฐœ ์ด ์ˆ˜์ต๋ฅ ์€ 62.5%์ž…๋‹ˆ๋‹ค. - ``` \ No newline at end of file + ``` \ No newline at end of file diff --git a/src/utils/ConsoleUtil.js b/src/utils/ConsoleUtil.js new file mode 100644 index 000000000..e71a792a5 --- /dev/null +++ b/src/utils/ConsoleUtil.js @@ -0,0 +1,15 @@ +import { Console } from "@woowacourse/mission-utils"; + +const ConsoleUtil = { + print(message) { + Console.print(message); + }, + readLine(prompt, callback) { + Console.readLine(prompt, callback); + }, + close() { + Console.close(); + }, + }; + + module.exports = ConsoleUtil; \ No newline at end of file From 1813921c3dc877e9c15941050895dc9acaba0302 Mon Sep 17 00:00:00 2001 From: hyeonjin6530 Date: Mon, 4 Nov 2024 22:25:18 +0900 Subject: [PATCH 04/10] =?UTF-8?q?fix:=20=EC=82=AC=EC=9A=A9=20=EC=9E=85?= =?UTF-8?q?=EC=B6=9C=EB=A0=A5=20=ED=95=A8=EC=88=98=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/errors/errorMessages.js | 0 src/utils/ConsoleUtil.js | 26 +++++++++++++------------- 2 files changed, 13 insertions(+), 13 deletions(-) create mode 100644 src/errors/errorMessages.js diff --git a/src/errors/errorMessages.js b/src/errors/errorMessages.js new file mode 100644 index 000000000..e69de29bb diff --git a/src/utils/ConsoleUtil.js b/src/utils/ConsoleUtil.js index e71a792a5..7d46fe33b 100644 --- a/src/utils/ConsoleUtil.js +++ b/src/utils/ConsoleUtil.js @@ -1,15 +1,15 @@ -import { Console } from "@woowacourse/mission-utils"; +const { Console } = require("@woowacourse/mission-utils"); const ConsoleUtil = { - print(message) { - Console.print(message); - }, - readLine(prompt, callback) { - Console.readLine(prompt, callback); - }, - close() { - Console.close(); - }, - }; - - module.exports = ConsoleUtil; \ No newline at end of file + print(message) { + Console.print(message); + }, + async readLine(prompt) { + return await Console.readLineAsync(prompt); + }, + close() { + Console.close(); + }, +}; + +module.exports = ConsoleUtil; From bec14a93b4bed83452212a3a10b7ea7b245944e3 Mon Sep 17 00:00:00 2001 From: hyeonjin6530 Date: Mon, 4 Nov 2024 22:25:54 +0900 Subject: [PATCH 05/10] =?UTF-8?q?feat:=20=EC=97=90=EB=9F=AC=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/errors/errorMessages.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/errors/errorMessages.js b/src/errors/errorMessages.js index e69de29bb..721693ed4 100644 --- a/src/errors/errorMessages.js +++ b/src/errors/errorMessages.js @@ -0,0 +1,9 @@ +const errorMessages = { + RANGE_OVER_ERROR: "[ERROR] ๋กœ๋˜ ๋ฒˆํ˜ธ๋Š” 1๋ถ€ํ„ฐ 45 ์‚ฌ์ด์˜ ์ˆซ์ž์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค.", + NOT_NUMBER_ERROR: "[ERROR] ๋กœ๋˜ ๋ฒˆํ˜ธ๋Š” ์ˆซ์ž์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค.", + INVALID_MONEY_ERROR: "[ERROR] ๊ตฌ์ž… ๊ธˆ์•ก์€ 1,000์› ๋‹จ์œ„๋กœ ์ž…๋ ฅํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.", + SAME_NUMBER_ERROR: "[ERROR] ๋กœ๋˜ ๋ฒˆํ˜ธ๋Š” ์ค‘๋ณต๋˜์ง€ ์•Š๋Š” 6๊ฐœ์˜ ์ˆซ์ž์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค.", + AMOUNT_OVER_ERROR: "[ERROR] ๋กœ๋˜ ๋ฒˆํ˜ธ๋Š” 6๊ฐœ์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค.", + }; + + module.exports = errorMessages; \ No newline at end of file From 942a6cf5ffd9b735b4fdbaa216c18a8d8f728900 Mon Sep 17 00:00:00 2001 From: hyeonjin6530 Date: Mon, 4 Nov 2024 22:27:54 +0900 Subject: [PATCH 06/10] =?UTF-8?q?feat:=20=EB=A1=9C=EB=98=90=20=EB=B2=88?= =?UTF-8?q?=ED=98=B8=20=EC=83=9D=EC=84=B1=20=EB=B0=8F=20=EC=97=90=EB=9F=AC?= =?UTF-8?q?=20=EA=B2=80=EC=82=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Lotto.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/Lotto.js b/src/Lotto.js index cb0b1527e..3ab1349ec 100644 --- a/src/Lotto.js +++ b/src/Lotto.js @@ -1,3 +1,5 @@ +const errorMessages = require("./errors/errorMessages"); + class Lotto { #numbers; @@ -8,11 +10,22 @@ class Lotto { #validate(numbers) { if (numbers.length !== 6) { - throw new Error("[ERROR] ๋กœ๋˜ ๋ฒˆํ˜ธ๋Š” 6๊ฐœ์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค."); + throw new Error(errorMessages.AMOUNT_OVER_ERROR); + } + if (new Set(numbers).size !== 6) { + throw new Error(errorMessages.SAME_NUMBER_ERROR); + } + if (numbers.some((num) => isNaN(num))) { + throw new Error(errorMessages.NOT_NUMBER_ERROR); + } + if (numbers.some((num) => num < 1 || num > 45)) { + throw new Error(errorMessages.RANGE_OVER_ERROR); } } - // TODO: ์ถ”๊ฐ€ ๊ธฐ๋Šฅ ๊ตฌํ˜„ + getNumbers() { + return [...this.#numbers].sort((a, b) => a - b); + } } -export default Lotto; +module.exports = Lotto; From 3fe61f1ad835981c4fcb75af3e4fd9262707fb31 Mon Sep 17 00:00:00 2001 From: hyeonjin6530 Date: Mon, 4 Nov 2024 22:30:06 +0900 Subject: [PATCH 07/10] =?UTF-8?q?feat:=20=EB=A1=9C=EB=98=90=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20=EB=B0=8F=20=EB=8B=B9=EC=B2=A8=20=EA=B2=B0=EA=B3=BC?= =?UTF-8?q?=20=EA=B3=84=EC=82=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/LottoManager.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/LottoManager.js diff --git a/src/LottoManager.js b/src/LottoManager.js new file mode 100644 index 000000000..bb917a0af --- /dev/null +++ b/src/LottoManager.js @@ -0,0 +1,33 @@ +const { Random } = require("@woowacourse/mission-utils"); +const Lotto = require("./Lotto"); + +class LottoManager { + constructor() { + this.lottos = []; + } + + generateLottos(count) { + this.lottos = Array.from({ length: count }, () => { + const numbers = Random.pickUniqueNumbersInRange(1, 45, 6); + return new Lotto(numbers); + }); + return this.lottos; + } + + calculateResults(winningNumbers, bonusNumber) { + const results = { 1: 0, 2: 0, 3: 0, 4: 0, 5: 0 }; + this.lottos.forEach((lotto) => { + const matchCount = lotto.getNumbers().filter((num) => winningNumbers.includes(num)).length; + const isBonusMatch = lotto.getNumbers().includes(bonusNumber); + + if (matchCount === 6) results[1]++; + else if (matchCount === 5 && isBonusMatch) results[2]++; + else if (matchCount === 5) results[3]++; + else if (matchCount === 4) results[4]++; + else if (matchCount === 3) results[5]++; + }); + return results; + } +} + +module.exports = LottoManager; From bdafea53f09d824587e8d566eceb77dbc7f89cdc Mon Sep 17 00:00:00 2001 From: hyeonjin6530 Date: Mon, 4 Nov 2024 22:43:53 +0900 Subject: [PATCH 08/10] =?UTF-8?q?feat:=20=EB=A1=9C=EB=98=90=20=EA=B2=8C?= =?UTF-8?q?=EC=9E=84=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.js | 102 +++++++++++++++++++++++++++++++++++- src/Lotto.js | 4 +- src/LottoManager.js | 24 +++++---- src/errors/errorMessages.js | 2 +- src/utils/ConsoleUtil.js | 7 +-- 5 files changed, 121 insertions(+), 18 deletions(-) diff --git a/src/App.js b/src/App.js index 091aa0a5d..029d4f75a 100644 --- a/src/App.js +++ b/src/App.js @@ -1,5 +1,105 @@ +import ConsoleUtil from "./utils/ConsoleUtil.js"; +import LottoManager from "./LottoManager.js"; +import errorMessages from "./errors/errorMessages.js"; + class App { - async run() {} + constructor() { + this.lottoManager = new LottoManager(); + } + + async run() { + try { + const amount = await ConsoleUtil.readLine("๊ตฌ์ž…๊ธˆ์•ก์„ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”.\n"); + this.#validateAmount(amount); + const lottoCount = Number(amount) / 1000; + const lottos = this.lottoManager.generateLottos(lottoCount); + + ConsoleUtil.print(`${lottoCount}๊ฐœ๋ฅผ ๊ตฌ๋งคํ–ˆ์Šต๋‹ˆ๋‹ค.`); + lottos.forEach((lotto) => ConsoleUtil.print(`[${lotto.getNumbers().join(", ")}]`)); + + await this.#getWinningNumbers(); + } catch (error) { + ConsoleUtil.print(error.message); + await this.run(); + } + } + + #validateAmount(amount) { + const num = Number(amount); + if (isNaN(num) || num % 1000 !== 0) { + throw new Error(errorMessages.INVALID_MONEY_ERROR); + } + return num; + } + + async #getWinningNumbers() { + try { + const winningNumbersInput = await ConsoleUtil.readLine("๋‹น์ฒจ ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”.\n"); + const winningNumbers = this.#parseNumbers(winningNumbersInput); + + const bonusNumberInput = await ConsoleUtil.readLine("๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”.\n"); + const bonusNumber = this.#parseBonusNumber(bonusNumberInput, winningNumbers); + + const results = this.lottoManager.calculateResults(winningNumbers, bonusNumber); + this.#printResults(results); + } catch (error) { + ConsoleUtil.print(error.message); + await this.#getWinningNumbers(); + } + } + + #parseNumbers(input) { + const numbers = input.split(",").map(Number); + if (numbers.length !== 6) { + throw new Error(errorMessages.AMOUNT_OVER_ERROR); + } + if (new Set(numbers).size !== 6) { + throw new Error(errorMessages.SAME_NUMBER_ERROR); + } + if (numbers.some((num) => isNaN(num))) { + throw new Error(errorMessages.NOT_NUMBER_ERROR); + } + if (numbers.some((num) => num < 1 || num > 45)) { + throw new Error(errorMessages.RANGE_OVER_ERROR); + } + return numbers; + } + + #parseBonusNumber(input, winningNumbers) { + const bonusNumber = Number(input); + if (isNaN(bonusNumber) || bonusNumber < 1 || bonusNumber > 45 || winningNumbers.includes(bonusNumber)) { + throw new Error(errorMessages.RANGE_OVER_ERROR); + } + return bonusNumber; + } + + #printResults(results) { + const prizeMap = { + 3: 5000, + 4: 50000, + 5: 1500000, + "5_bonus": 30000000, + 6: 2000000000, + }; + + ConsoleUtil.print("๋‹น์ฒจ ํ†ต๊ณ„\n---"); + ConsoleUtil.print(`3๊ฐœ ์ผ์น˜ (5,000์›) - ${results[3]}๊ฐœ`); + ConsoleUtil.print(`4๊ฐœ ์ผ์น˜ (50,000์›) - ${results[4]}๊ฐœ`); + ConsoleUtil.print(`5๊ฐœ ์ผ์น˜ (1,500,000์›) - ${results[5]}๊ฐœ`); + ConsoleUtil.print(`5๊ฐœ ์ผ์น˜, ๋ณด๋„ˆ์Šค ๋ณผ ์ผ์น˜ (30,000,000์›) - ${results["5_bonus"]}๊ฐœ`); + ConsoleUtil.print(`6๊ฐœ ์ผ์น˜ (2,000,000,000์›) - ${results[6]}๊ฐœ`); + + const totalEarnings = + results[3] * prizeMap[3] + + results[4] * prizeMap[4] + + results[5] * prizeMap[5] + + results["5_bonus"] * prizeMap["5_bonus"] + + results[6] * prizeMap[6]; + + const investment = this.lottoManager.lottos.length * 1000; + const profitRate = ((totalEarnings / investment) * 100).toFixed(1); + ConsoleUtil.print(`์ด ์ˆ˜์ต๋ฅ ์€ ${profitRate}%์ž…๋‹ˆ๋‹ค.`); + } } export default App; diff --git a/src/Lotto.js b/src/Lotto.js index 3ab1349ec..8353612dd 100644 --- a/src/Lotto.js +++ b/src/Lotto.js @@ -1,4 +1,4 @@ -const errorMessages = require("./errors/errorMessages"); +import errorMessages from "./errors/errorMessages.js"; class Lotto { #numbers; @@ -28,4 +28,4 @@ class Lotto { } } -module.exports = Lotto; +export default Lotto; diff --git a/src/LottoManager.js b/src/LottoManager.js index bb917a0af..52c416c96 100644 --- a/src/LottoManager.js +++ b/src/LottoManager.js @@ -1,5 +1,5 @@ -const { Random } = require("@woowacourse/mission-utils"); -const Lotto = require("./Lotto"); +import { Random } from "@woowacourse/mission-utils"; +import Lotto from "./Lotto.js"; class LottoManager { constructor() { @@ -15,19 +15,25 @@ class LottoManager { } calculateResults(winningNumbers, bonusNumber) { - const results = { 1: 0, 2: 0, 3: 0, 4: 0, 5: 0 }; + const results = { 3: 0, 4: 0, 5: 0, "5_bonus": 0, 6: 0 }; this.lottos.forEach((lotto) => { const matchCount = lotto.getNumbers().filter((num) => winningNumbers.includes(num)).length; const isBonusMatch = lotto.getNumbers().includes(bonusNumber); - if (matchCount === 6) results[1]++; - else if (matchCount === 5 && isBonusMatch) results[2]++; - else if (matchCount === 5) results[3]++; - else if (matchCount === 4) results[4]++; - else if (matchCount === 3) results[5]++; + if (matchCount === 6) { + results[6]++; + } else if (matchCount === 5 && isBonusMatch) { + results["5_bonus"]++; + } else if (matchCount === 5) { + results[5]++; + } else if (matchCount === 4) { + results[4]++; + } else if (matchCount === 3) { + results[3]++; + } }); return results; } } -module.exports = LottoManager; +export default LottoManager; diff --git a/src/errors/errorMessages.js b/src/errors/errorMessages.js index 721693ed4..98217eaec 100644 --- a/src/errors/errorMessages.js +++ b/src/errors/errorMessages.js @@ -6,4 +6,4 @@ const errorMessages = { AMOUNT_OVER_ERROR: "[ERROR] ๋กœ๋˜ ๋ฒˆํ˜ธ๋Š” 6๊ฐœ์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค.", }; - module.exports = errorMessages; \ No newline at end of file + export default errorMessages; \ No newline at end of file diff --git a/src/utils/ConsoleUtil.js b/src/utils/ConsoleUtil.js index 7d46fe33b..e9c049f2e 100644 --- a/src/utils/ConsoleUtil.js +++ b/src/utils/ConsoleUtil.js @@ -1,4 +1,4 @@ -const { Console } = require("@woowacourse/mission-utils"); +import { Console } from "@woowacourse/mission-utils"; const ConsoleUtil = { print(message) { @@ -7,9 +7,6 @@ const ConsoleUtil = { async readLine(prompt) { return await Console.readLineAsync(prompt); }, - close() { - Console.close(); - }, }; -module.exports = ConsoleUtil; +export default ConsoleUtil; From 87e68d6c923f8c478d71ecad51c54120d6a60b35 Mon Sep 17 00:00:00 2001 From: hyeonjin6530 Date: Mon, 4 Nov 2024 22:49:04 +0900 Subject: [PATCH 09/10] =?UTF-8?q?feat:=20=EA=B2=B0=EA=B3=BC=20=EC=B6=9C?= =?UTF-8?q?=EB=A0=A5=20=EC=BD=94=EB=93=9C=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.js | 37 +++++-------------------------------- src/ResultPrinter.js | 27 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 32 deletions(-) create mode 100644 src/ResultPrinter.js diff --git a/src/App.js b/src/App.js index 029d4f75a..9ee413c74 100644 --- a/src/App.js +++ b/src/App.js @@ -1,6 +1,7 @@ import ConsoleUtil from "./utils/ConsoleUtil.js"; import LottoManager from "./LottoManager.js"; import errorMessages from "./errors/errorMessages.js"; +import ResultPrinter from "./ResultPrinter.js"; class App { constructor() { @@ -17,7 +18,7 @@ class App { ConsoleUtil.print(`${lottoCount}๊ฐœ๋ฅผ ๊ตฌ๋งคํ–ˆ์Šต๋‹ˆ๋‹ค.`); lottos.forEach((lotto) => ConsoleUtil.print(`[${lotto.getNumbers().join(", ")}]`)); - await this.#getWinningNumbers(); + await this.#getWinningNumbers(lottoCount); } catch (error) { ConsoleUtil.print(error.message); await this.run(); @@ -32,7 +33,7 @@ class App { return num; } - async #getWinningNumbers() { + async #getWinningNumbers(lottoCount) { try { const winningNumbersInput = await ConsoleUtil.readLine("๋‹น์ฒจ ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”.\n"); const winningNumbers = this.#parseNumbers(winningNumbersInput); @@ -41,10 +42,10 @@ class App { const bonusNumber = this.#parseBonusNumber(bonusNumberInput, winningNumbers); const results = this.lottoManager.calculateResults(winningNumbers, bonusNumber); - this.#printResults(results); + ResultPrinter.printResults(results, lottoCount); } catch (error) { ConsoleUtil.print(error.message); - await this.#getWinningNumbers(); + await this.#getWinningNumbers(lottoCount); } } @@ -72,34 +73,6 @@ class App { } return bonusNumber; } - - #printResults(results) { - const prizeMap = { - 3: 5000, - 4: 50000, - 5: 1500000, - "5_bonus": 30000000, - 6: 2000000000, - }; - - ConsoleUtil.print("๋‹น์ฒจ ํ†ต๊ณ„\n---"); - ConsoleUtil.print(`3๊ฐœ ์ผ์น˜ (5,000์›) - ${results[3]}๊ฐœ`); - ConsoleUtil.print(`4๊ฐœ ์ผ์น˜ (50,000์›) - ${results[4]}๊ฐœ`); - ConsoleUtil.print(`5๊ฐœ ์ผ์น˜ (1,500,000์›) - ${results[5]}๊ฐœ`); - ConsoleUtil.print(`5๊ฐœ ์ผ์น˜, ๋ณด๋„ˆ์Šค ๋ณผ ์ผ์น˜ (30,000,000์›) - ${results["5_bonus"]}๊ฐœ`); - ConsoleUtil.print(`6๊ฐœ ์ผ์น˜ (2,000,000,000์›) - ${results[6]}๊ฐœ`); - - const totalEarnings = - results[3] * prizeMap[3] + - results[4] * prizeMap[4] + - results[5] * prizeMap[5] + - results["5_bonus"] * prizeMap["5_bonus"] + - results[6] * prizeMap[6]; - - const investment = this.lottoManager.lottos.length * 1000; - const profitRate = ((totalEarnings / investment) * 100).toFixed(1); - ConsoleUtil.print(`์ด ์ˆ˜์ต๋ฅ ์€ ${profitRate}%์ž…๋‹ˆ๋‹ค.`); - } } export default App; diff --git a/src/ResultPrinter.js b/src/ResultPrinter.js new file mode 100644 index 000000000..42c3f655d --- /dev/null +++ b/src/ResultPrinter.js @@ -0,0 +1,27 @@ +import ConsoleUtil from "./utils/ConsoleUtil.js"; + +export default class ResultPrinter { + static printResults(results, lottoCount) { + const prizeMap = { + 3: { amount: 5000, label: "3๊ฐœ ์ผ์น˜ (5,000์›)" }, + 4: { amount: 50000, label: "4๊ฐœ ์ผ์น˜ (50,000์›)" }, + 5: { amount: 1500000, label: "5๊ฐœ ์ผ์น˜ (1,500,000์›)" }, + "5_bonus": { amount: 30000000, label: "5๊ฐœ ์ผ์น˜, ๋ณด๋„ˆ์Šค ๋ณผ ์ผ์น˜ (30,000,000์›)" }, + 6: { amount: 2000000000, label: "6๊ฐœ ์ผ์น˜ (2,000,000,000์›)" }, + }; + + ConsoleUtil.print("๋‹น์ฒจ ํ†ต๊ณ„\n---"); + let totalEarnings = 0; + + Object.keys(prizeMap).forEach((key) => { + const count = results[key] || 0; + const prize = prizeMap[key]; + totalEarnings += count * prize.amount; + ConsoleUtil.print(`${prize.label} - ${count}๊ฐœ`); + }); + + const investment = lottoCount * 1000; + const profitRate = ((totalEarnings / investment) * 100).toFixed(1); + ConsoleUtil.print(`์ด ์ˆ˜์ต๋ฅ ์€ ${profitRate}%์ž…๋‹ˆ๋‹ค.`); + } +} From 2e75aeba98608dec3b2ebbba5da4845f7efe4103 Mon Sep 17 00:00:00 2001 From: hyeonjin6530 Date: Mon, 4 Nov 2024 22:51:52 +0900 Subject: [PATCH 10/10] =?UTF-8?q?feat:=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __tests__/LottoTest.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/__tests__/LottoTest.js b/__tests__/LottoTest.js index 409aaf69b..b0828dbac 100644 --- a/__tests__/LottoTest.js +++ b/__tests__/LottoTest.js @@ -15,4 +15,18 @@ describe("๋กœ๋˜ ํด๋ž˜์Šค ํ…Œ์ŠคํŠธ", () => { }); // TODO: ์ถ”๊ฐ€ ๊ธฐ๋Šฅ ๊ตฌํ˜„์— ๋”ฐ๋ฅธ ํ…Œ์ŠคํŠธ ์ฝ”๋“œ ์ž‘์„ฑ + test("๋กœ๋˜ ๋ฒˆํ˜ธ์— ์ˆซ์ž๊ฐ€ ์•„๋‹Œ ๊ฐ’์ด ํฌํ•จ๋˜๋ฉด ์˜ˆ์™ธ๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค.", () => { + expect(() => { + new Lotto([1, 2, 3, 4, 5, "a"]); + }).toThrow("[ERROR]"); + expect(() => { + new Lotto([1, 2, 3, 4, 5, null]); + }).toThrow("[ERROR]"); + }); + + test("๋กœ๋˜ ๋ฒˆํ˜ธ๊ฐ€ 6๊ฐœ์˜ ๊ณ ์œ ํ•œ ์ˆซ์ž๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ์„ ๊ฒฝ์šฐ ์˜ˆ์™ธ๊ฐ€ ๋ฐœ์ƒํ•˜์ง€ ์•Š๋Š”๋‹ค.", () => { + expect(() => { + new Lotto([1, 2, 3, 4, 5, 6]); + }).not.toThrow(); + }); });