Open
Conversation
yssccc
reviewed
Nov 5, 2025
yssccc
left a comment
There was a problem hiding this comment.
MVC 패턴에 따라 역할 분리를 꼼꼼히 하신 게 느껴지는 코드였습니다😀 3주 차 미션도 고생하셨습니다!!
Comment on lines
+14
to
+16
| getNumbers() { | ||
| return this.#numbers; | ||
| } |
There was a problem hiding this comment.
배열을 직접 반환하게 되면 외부에서 변경할 수 있기 때문에 복사본을 반환하는 게 불변성 측면에서 좋을 것 같습니다!
Comment on lines
+5
to
+9
| export function formatNumber(number) { | ||
| return number.toLocaleString('ko-KR', { | ||
| maximumFractionDigits: 1, | ||
| }); | ||
| } |
Author
There was a problem hiding this comment.
여러 방법을 알아봤는데 나라별로 쓰이는 형식으로 자동 변환해주는 js 내장 함수더라고요!
|
|
||
| calculateLottoCount() { | ||
| const money = Number(this.#money); | ||
| return money / 1000; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
javascript-lotto-precourse
🔆 프로젝트 큰 흐름
InputView를 통해 로또 구입 금액 문자열을 입력 받는다.PurchaseAmount모델을 생성하며PurchaseAmountValidator를 통해 유효성 검사를 실행한다.[ERROR]메시지를 출력하고 해당 지점부터 다시 입력을 받는다.LottoStore모델을 통해PurchaseAmount만큼 로또(Lotto인스턴스)를 구매한다.Random.pickUniqueNumbersInRange를 사용해 로또 번호를 생성한다.OutputView를 통해 구매한 로또 개수와 번호 목록을 출력한다.InputView를 통해 당첨 번호 문자열을 입력 받는다.WinningLottoValidator로 문자열 포맷(쉼표, 공백 등)을 검사한다.Lotto모델을 생성하며LottoValidator로 6개의 번호에 대한 유효성(개수, 중복, 범위)을 검사한다.[ERROR]메시지를 출력하고 다시 입력을 받는다.InputView를 통해 보너스 번호 문자열을 입력 받는다.WinningLotto모델을 생성하며WinningLottoValidator로 보너스 번호의 유효성(범위, 당첨 번호와 중복 여부)을 검사한다.[ERROR]메시지를 출력하고 다시 입력을 받는다.LottoResult모델을 생성자에 구매한 로또 배열과WinningLotto를 전달하여 생성한다.LottoResult는 내부적으로 모든 로또를WinningLotto와 비교하여 당첨 통계를 계산한다.OutputView를 통해 당첨 통계 헤더 문구를 출력한다.OutputView를 통해 등수별 당첨 개수와 수익률을 포맷에 맞게 출력한다.📁 프로젝트 구조
✅ 구현할 기능 목록
[공통]
App.js의run()메서드를 구현하여 프로그램 전체 흐름 제어LottoGameController.js의play()메서드에서 메인 로직 흐름 관리constants폴더에 모든 입력/출력/에러 메시지와 설정을 정의[ERROR]가 포함된 메시지를 출력하고 해당 입력부터 다시 받도록 구현[View]
InputView: 구입 금액을 입력 받는 기능 구현InputView: 당첨 번호를 입력 받는 기능 구현InputView: 보너스 번호를 입력 받는 기능 구현OutputView: 구매한 로또 개수와 번호 목록을 출력하는 기능 구현OutputView: 당첨 통계 헤더("당첨 통계\n---")를 출력하는 기능 구현OutputView: 각 등수별 당첨 결과를 포맷에 맞게 출력하는 기능 구현OutputView: 총 수익률을 소수점 둘째 자리에서 반올림하여 출력하는 기능 구현[Validator]
Validator: 입력값이 비어있지 않은지 검증Validator: 값이 양의 정수인지 검증Validator: 값이 1~45 사이의 숫자인지 검증Validator: 배열 내 중복된 숫자가 있는지 검증MoneyValidator: 구입 금액이 1,000원 단위인지 검증MoneyValidator: 구입 금액이Number.MAX_SAFE_INTEGER를 넘지 않는지 검증WinningLottoValidator: 당첨 번호 문자열에 구분자(,)가 포함되어 있는지 검증WinningLottoValidator: 당첨 번호 문자열이 구분자(,)로 시작하거나 끝나지 않는지 검증LottoValidator: 로또 번호가 6개인지 검증WinningLottoValidator: 보너스 번호가 당첨 번호 6개와 중복되지 않는지 검증[Model]
property:#numbers(오름차순 정렬)method:getNumbers()method:compare(lottoNumbers)(로또 1장과 비교하여 {일치 개수, 보너스 일치 여부} 반환)method:buyLottos(purchaseAmount)(구입 금액만큼 로또 생성)method:#calculateStats(...)(모든 로또의 당첨 등수 계산)method:#calculateProfit(...)(총 투자 대비 수익률 계산)method:getMatchCntInfo(),getProfitRate()[Utils]
Utils.js:splitBySeparator(문자열을 구분자로 나누어 배열 반환)Utils.js:formatNumber(숫자를 1,000 단위 쉼표가 있는 문자열로 변환)@woowacourse/mission-utils:Random.pickUniqueNumbersInRange를 사용해 랜덤 번호 생성@woowacourse/mission-utils:Console.readLineAsync와Console.print로 입출력 처리0. 공통
1. 로또 구입 금액 (money)
2. 당첨 번호 문자열 (winningNumberString)
3. 당첨 번호 배열 (winningNumbers)
4. 보너스 번호 (bonusNumber)