Open
Conversation
added 29 commits
November 2, 2025 22:40
구현하는 로또 미션의 흐름에 따라 기능들을 나누고 이를 effect가 있는 액션인지 순수함수인 계산인지를 구분하였습니다.
기존의 작성된 기능 목록을 effect와 pure 기준으로 구조적으로 분리했습니다. 분리한 이유는 순수 계산 기능을 먼저 구현하기 위함입니다.
당첨 번호와 티켓 사이에 일치하는 숫자의 개수를 계산하는 함수를 구현하였습니다. set를 사용해서 중복되지 않았을 때의 길이에서 Set()의 size를 빼주는 방식으로 구현했습니다.
로또 번호가 보너스 번호를 포함하고 있는지 확인합니다. 해당 로직은 검증에서도 사용되기 떄문에 실제 로직은 util에 두고 domain에서 래핑해서 사용합니다.
일치하는 숫자의 개수와 보너스 여부를 가지고 등수를 결정합니다. 랭크 테이블을 상수로 추가 정의하여서 등수 탐색합니다.
상금 테이블을 통해서 랭크에 따른 수익 누적합을 계산합니다.
수익률을 퍼센트로 계산하는 함수를 구현하였습니다. 소수점을 처리하는 부분은 출력에 대한 표현으로 정의하고 퍼센트 연산의 정확한 결과를 반환합니다. 추후 확장되어 해당 값을 가지고 다른 계산이 필요할 때 정확한 연산을 할 수 있습니다.
기존 도메인 테스트 파일을 각 도메인별 유닛 테스트 파일로 분리하였습니다.
로또 번호가 1~45 범위인지를 검증하는 함수를 구현하였습니다.
Set를 이용하여 로또 번호과 중복되지 않음을 검증합니다.
로또 사이즈(6)와 일치하는 지 검증하는 함수를 구현하였습니다.
보너스 번호가 1~45 사이의 숫자인지, 당첨 번호와 중복되지 않는지 검증합니다.
문자열을 쉼표를 기준으로 나누어 숫자 배열을 만드는 util함수를 구현했습니다. toNumber() 함수를 분리하여 구입 금액이나 숫자를 입력 받을 때 재사용할 수 있습니다.
구입 금액으로 부터 티켓의 수를 구하기 위한 나눗셈 함수 구현하였습니다.
랜덤 숫자를 생성하는 함수를 인자로 받아 로또 규칙을 준수하는 로또 번호를 생성합니다.
로또 티켓 수만큼의 로또 숫자 세트를 생성합니다.
manNomi
reviewed
Nov 10, 2025
manNomi
left a comment
There was a problem hiding this comment.
코드가 전반적으로 깔끔하고 잘작성되있어서
금방 리뷰할 수 있었습니다
좋은 코드 덕분에 많이배웠습니다!
| - [x] `로또 시뮬레이션 결과 출력 액션` | ||
| - [x] 발행한 로또의 수량과 번호을 출력한다. | ||
| - [x] 당첨 내역을 출력한다. | ||
| - [x] 수익률을 출력한다. No newline at end of file |
| async run() {} | ||
| async run() { | ||
| const purchasedAmount = await readPurchasedAmountUntilValid(); | ||
| const ticketAmount = devisionNumber(purchasedAmount, LOTTO_CONSTANTS.TICKET_PRICE); |
There was a problem hiding this comment.
devisionNumber 함수를 쓰신 이유가 있을까요 ?
purchasedAmount / LOTTO_CONSTANTS.TICKET_PRICE
가 좀더 깔끔해 보이는것 같기도 하고요 ...
devisionNumber함수가 무엇을 하는지 이름을 보고 파악은했지만 혹시라도 모르니 함수를 한번더 확인하게 되더라고요
| // 5개만 생성 확인 | ||
| expect(createLottos(5, randomUniquesInRange).length).toBe(5); | ||
| }) | ||
| }) No newline at end of file |
| } | ||
|
|
||
| export const isIntegerValue = (value) => Number.isInteger(value); | ||
| export const isNaNValue = (value) => Number.isNaN(value); No newline at end of file |
There was a problem hiding this comment.
유틸의 index.js 가 있는데 배럴파일 일것이라 예상했는데 util의 common이 강한 코드가 있었습니다
common.js 같은 이름으로 수정해도 좋을것 같긴합니다 !
| const { MIN_NUMBER, MAX_NUMBER, NUMBERS_PER_TICKET } = LOTTO_CONSTANTS | ||
| const numbers = drawUniqueNumbers( MIN_NUMBER, MAX_NUMBER, NUMBERS_PER_TICKET ); | ||
| return new Lotto(numbers); | ||
| }; |
There was a problem hiding this comment.
코드 detph가 너무 깊은것 같습니다!!
랜덤 함수가 타고타고타고 내려가서 주입 패턴이 다소 헷갈리게 하는것 같습니다
여기에서 선언안하시고 상위에서 주입하신 이유가 있을까요 ?
랜덤 함수가 추후에 바뀌는것을 대비해서 랜덤 모듈을 손쉽게 갈아끼기 위함 입니까?
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.
기능 목록
Pure(순수 계산: 계산/검증/도메인)
입력값을 필요한 형태로 파싱 계산사용자의 입력값 검증 계산구매량 만큼 로또를 만드는 계산당첨 번호와 로또 번호를 비교/채점하는 계산로또 수익률을 계산Effect(부수효과 액션: 입출력/난수/에러)
사용자의 입력 액션에러 발생 액션사용자에게 재입력 액션난수를 생성 액션로또 시뮬레이션 결과 출력 액션