-
Notifications
You must be signed in to change notification settings - Fork 190
[로또] 권순재 미션 제출합니다. #169
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
base: main
Are you sure you want to change the base?
[로또] 권순재 미션 제출합니다. #169
Conversation
yssccc
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MVC 패턴에 따라 역할 분리를 꼼꼼히 하신 게 느껴지는 코드였습니다😀 3주 차 미션도 고생하셨습니다!!
| getNumbers() { | ||
| return this.#numbers; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
배열을 직접 반환하게 되면 외부에서 변경할 수 있기 때문에 복사본을 반환하는 게 불변성 측면에서 좋을 것 같습니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
피드백 감사합니다!
| export function formatNumber(number) { | ||
| return number.toLocaleString('ko-KR', { | ||
| maximumFractionDigits: 1, | ||
| }); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이런 방법도 있네요..배워갑니당..👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
여러 방법을 알아봤는데 나라별로 쓰이는 형식으로 자동 변환해주는 js 내장 함수더라고요!
|
|
||
| calculateLottoCount() { | ||
| const money = Number(this.#money); | ||
| return money / 1000; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
상수화한 LOTTO_COST를 사용하면 좋을 것 같아요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
앗 그렇네요..! 캐치해주셔서 감사합니다 :)
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)