[우테코 스터디] 로또 다시 구현하기 - #1
Conversation
- 수정 : printPurchaseNumber(purchasQuantity) 수량을 매개변수로 받아서 출력되도록 만듬. - 추가 : printLottoNumber(value) 로또번호를 그대로 받아 바로 출력해주도록 만듬.
…경, Import를 위한 export문이 {}형태로 여러가지를 export 하는 것이로 변경.
…gNumber를 받을 수 있도록 만들고, validation에서 사용됨
rosielsh
left a comment
There was a problem hiding this comment.
2주차도 수고 많으셨습니다!
코드 리뷰에서 언급한 부분을 검토해보시고, 개선할 수 있는 부분이 있다면 반영해보시면 좋을 것 같아요.
다음 주차도 화이팅입니다 🚀
| #validate(numbers) { | ||
| if (numbers.length !== 6) { | ||
| throw new Error("[ERROR] 로또 번호는 6개여야 합니다."); | ||
| throw new Error('[ERROR] 로또 번호는 6개여야 합니다.'); |
| isDuplicatedInWinningNumber: createMsg('당첨번호와 중복되는 번호를 입력하셨습니다.'), | ||
| }; | ||
|
|
||
| export { ERROR_PREFIX, ERROR_MESSAGES }; |
There was a problem hiding this comment.
ERROR_PREFIX는 외부에서 사용하지 않는다면 굳이 export할 필요가 없을 것 같아요 !
| const INPUT_MESSAGES = { | ||
| whatPurchaseAmount: '구매금액을 입력해주세요. \n => ', | ||
| winningNumber: '당첨번호를 입력해주세요. \n => ', | ||
| bonusNumber: '보너스번호를 입력해주세요. \n => ', |
There was a problem hiding this comment.
=> 는 미션의 출력 형식에는 포함되어있지 않아서, 미션의 요구사항에 맞추려면 출력값을 동일하게 설정하는 것이 어떨까 생각합니다 :)
| import { MissionUtils } from '@woowacourse/mission-utils'; | ||
| import OutputView from '../view/OutputView.js'; | ||
|
|
||
| class PrintRandomNumber { | ||
| printRandomNumber(purchasQuantity) { | ||
| OutputView.printPurchaseNumber(purchasQuantity); | ||
| let lottoNumberArrayss = []; | ||
| for (let i = 0; i < purchasQuantity; i++) { | ||
| const lottoNumber = MissionUtils.Random.pickUniqueNumbersInRange(1, 45, 6); | ||
| const ascendingOrder = lottoNumber.sort((a, b) => a - b); | ||
| OutputView.printLottoNumber(ascendingOrder); | ||
| lottoNumberArrayss = [...lottoNumberArrayss, ascendingOrder]; | ||
| } | ||
| OutputView.printSpace(); | ||
| return lottoNumberArrayss; | ||
| } | ||
| } | ||
|
|
||
| export default PrintRandomNumber; |
There was a problem hiding this comment.
해당 파일과 OutputView에서 모두 Console 라이브러리를 import해서 출력하는 동일한 역할을 한다고 생각되는데요 ! 특별히 이 함수만 모듈로 분리한 이유가 있으신지 궁금합니다 :)
| const vlaidatedInput = await this.errorCatch(); | ||
| if (vlaidatedInput) return vlaidatedInput; | ||
| if (i === 5) throw new Error(ERROR_MESSAGES.enteredMoreFiveTimes); | ||
| } |
| const commonResult = { matchNum: matchedNumbers, matchBonus: matchedBonus }; | ||
| return (commonNumbers = [...commonNumbers, commonResult]); | ||
| }); | ||
| return commonNumbers; |
There was a problem hiding this comment.
map은 새로운 배열을 반환하도록 설계되었는데, 여기서는 그 반환값을 사용하지 않고 있어서 forEach를 사용하는 것이 더 적절해 보입니다!
dlsxjzld
left a comment
There was a problem hiding this comment.
고생 많으셨습니다!!
개인적인 회고와 어려웠던 부분에서 공감가는 부분이 많네요!!
다음 주도 화이팅입니다! 👍
| @@ -0,0 +1,20 @@ | |||
| const ERROR_PREFIX = '[ERROR]'; | |||
|
|
|||
| const createMsg = (msg) => `${ERROR_PREFIX} ${msg} ${'다시 입력해주세요.'}\n`; | |||
There was a problem hiding this comment.
다시 입력해주세요. 부분은 일반 문자열이라 ${}밖에 있어도 괜찮을 것 같아요! 🤔
|
|
||
| const createMsg = (msg) => `${ERROR_PREFIX} ${msg} ${'다시 입력해주세요.'}\n`; | ||
|
|
||
| const ERROR_MESSAGES = { |
| async repeatInput() { | ||
| for (let i = 0; i < 10; i++) { | ||
| const vlaidatedInput = await this.errorCatch(); | ||
| if (vlaidatedInput) return vlaidatedInput; | ||
| if (i === 5) throw new Error(ERROR_MESSAGES.enteredMoreFiveTimes); | ||
| } | ||
| } |
There was a problem hiding this comment.
repeatInput()이 반복되는 것 같은데 클래스의 상속이나 함수 등으로 모듈화 시켜도 좋을 것 같아요! 👍
| import { MissionUtils } from '@woowacourse/mission-utils'; | ||
| import OutputView from '../view/OutputView.js'; | ||
|
|
||
| class PrintRandomNumber { | ||
| printRandomNumber(purchasQuantity) { | ||
| OutputView.printPurchaseNumber(purchasQuantity); | ||
| let lottoNumberArrayss = []; | ||
| for (let i = 0; i < purchasQuantity; i++) { | ||
| const lottoNumber = MissionUtils.Random.pickUniqueNumbersInRange(1, 45, 6); | ||
| const ascendingOrder = lottoNumber.sort((a, b) => a - b); | ||
| OutputView.printLottoNumber(ascendingOrder); | ||
| lottoNumberArrayss = [...lottoNumberArrayss, ascendingOrder]; | ||
| } | ||
| OutputView.printSpace(); | ||
| return lottoNumberArrayss; | ||
| } | ||
| } | ||
|
|
||
| export default PrintRandomNumber; |
| const calculThree = winningStatistics[0].matchThree * 5000; | ||
| const calculFour = winningStatistics[1].matchFour * 50000; | ||
| const calculFive = winningStatistics[2].matchFive * 1500000; | ||
| const calculFiveAndBonus = winningStatistics[3].matchFiveAndBonus * 30000000; |
There was a problem hiding this comment.
30000000 대신 30_000_000 이렇게 입력하면 더 가독성 있을 것 같아요 👍
There was a problem hiding this comment.
언더스코어로 표현해도 숫자로 인지가 되나 보네요 :) 저도 배우고 갑니다.
There was a problem hiding this comment.
저도 이 사실을 이번에 처음 알게 되었습니다. 알려주셔서 감사합니다. ㅎㅎ
| async printPurchaseNumber(purchasQuantity) { | ||
| MissionUtils.Console.print(`${purchasQuantity}${OUTPUT_MESSAGES.purchaseNumber}`); | ||
| }, |
There was a problem hiding this comment.
웹 프론트엔드 3주차 공통 피드백의 객체는 객체답게 사용한다에 로또 파일을 사용하는 방법이 좀 나와있는 것 같아요!! 도움이 되면 좋겠네요 😊
jinnyjiinlee
left a comment
There was a problem hiding this comment.
보람님, 이번 주도 정말 고생 많으셨어요!
보람님께서 남겨주신 고민에 대해 저의 생각을 정리해 보았습니다. 😊
- 유효성 검사에 시간을 많이 소비하고 계신 점
저도 비슷한 경험이 있었어요. 프로젝트마다 유효성 검사가 반복적으로 등장하다 보니, 이전에 작성했던 코드를 복사해서 사용하는 방식을 선택하게 되었어요.
예를 들어, 로또 프로젝트를 할 때 이전에 진행했던 자동차 경주 게임에서 사용했던 유효성 검사 코드 중 중복되는 부분을 그대로 가져오고, 변수명과 몇 가지 필요한 부분만 수정했어요.
이 방법을 사용하니 시간이 상당히 단축되었습니다.
- Lotto.js 파일 사용에 어려움을 겪고 계신 점
Lotto.js 파일을 반드시 사용해야 한다는 조건 때문에 어려움을 겪고 계신다고 하셨는데, 이 부분은 더 구체적으로 말씀해 주시면 좋을 것 같아요.
혹시 유효성 검사 관련 부분이라면, 제가 사용했던 방식이나 아는 부분을 공유드릴게요.
같이 고민하면 해결 방법을 더 쉽게 찾을 수 있을 것 같아요. 😄
- 당첨 내역 및 수익률 출력에서 어려움을 겪고 계신 점
이 부분은 어떤 점에서 어려움을 느끼셨는지 조금 더 구체적으로 알려주시면 좋을 것 같습니다.
예를 들어:
수익률 계산(= 당첨 금액 / 총 구매 금액) 자체가 어려운 것인지,
변수를 관리하기 위해 모듈화를 하고 import하는 과정이 어려운 것인지,
아니면 당첨 내역을 매칭시키는 로직을 구현하는 게 복잡하게 느껴지신 것일까요?
구체적으로 말씀해 주시면 제가 사용하는 방법이나 팁을 공유드릴게요! 도움이 되었으면 좋겠습니다. 🙌
너무 수고 많으셨습니다! 😊
| emptyValue: createMsg('값이 존재하지 않습니다.'), | ||
| regexpTest: createMsg('형식이 잘 못되었습니다.'), | ||
| startComma: createMsg('입력이 콤마(,)부터 시작할 수 없습니다.'), | ||
| endComma: createMsg('입력 끝에 콤마(,)로 끝날 수 없습니다.'), | ||
| enteredMoreFiveTimes: '5회 이상 잘못 입력하여 종료되없습니다. 다시 실행해주세요.', | ||
| limitDigits: createMsg('최소 4자리 숫자부터 6자리 숫자까지 입력 가능합니다.'), | ||
| negativeNumber: createMsg('음수가 입력될 수 없습니다.'), | ||
| thousandUnit: createMsg( | ||
| '로또 금액인 1000원 단위로만 입력 가능하며, 최대 10만원까지 입력 가능합니다.' | ||
| ), | ||
| winningNumberSixDigit: createMsg('당첨번호는 6자리를 입력해야합니다.'), | ||
| isDuplicatedInWinningNumber: createMsg('당첨번호와 중복되는 번호를 입력하셨습니다.'), | ||
| }; | ||
|
|
| @@ -0,0 +1,5 @@ | |||
| const createThrowError = (message) => { | |||
| throw new Error(`${message}`); | |||
There was a problem hiding this comment.
${message}가 아니라 message만 바로 써도 되는데, 혹시 다른 이유가 있어서 사용하신지 궁금합니다!
There was a problem hiding this comment.
이유는 없었습니다. 복사해오면서 혹시나 다른 것으로 사용할까 해서 수정을 안했던 것이였습니다~
There was a problem hiding this comment.
@boramson 아하! 네~ 그럼 리펙토링 할 때 변수명만 나오게 수정하면 좋을 것 같습니다 :)
| lottoNumberArrayss = [...lottoNumberArrayss, ascendingOrder]; | ||
| } |
There was a problem hiding this comment.
lottoNumberArrayss 마지막 s를 한번 더 적으셔서 오타가 있는 것 같습니다!
| const calculThree = winningStatistics[0].matchThree * 5000; | ||
| const calculFour = winningStatistics[1].matchFour * 50000; | ||
| const calculFive = winningStatistics[2].matchFive * 1500000; | ||
| const calculFiveAndBonus = winningStatistics[3].matchFiveAndBonus * 30000000; |
There was a problem hiding this comment.
언더스코어로 표현해도 숫자로 인지가 되나 보네요 :) 저도 배우고 갑니다.
| import InputPurchaseModule from '../modules/InputPurchaseModule.js'; | ||
| import InputWinningModule from '../modules/InputWinningModule.js'; | ||
| import InputBonusModule from '../modules/InputBonusModule.js'; | ||
| import PrintWinningDetails from '../modules/printWinningDetails.js'; |
There was a problem hiding this comment.
보람님의 로또 프로젝트를 실행을 해봤는데, 에러가 납니다.
node:internal/modules/esm/resolve:265
throw new ERR_MODULE_NOT_FOUND(
^
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/workspaces/javascript-lotto-7/src/modules/printWinningDetails.js' imported from /workspaces/javascript-lotto-7/src/controller/LottoController.js
LottoController.js파일 import부분
import PrintWinningDetails from '../modules/printWinningDetails.js';
이 부분에 파일명은 대문자로 시작을 해서 연결이 안되었네요!
vscode환경에서는 대소문자는 허용되는 경우가 있어서, 최종 코테 과제 제출하실 때 꼼꼼히 확인해보시면 좋을 것 같아요~
|
|
||
| async runLotto() { | ||
| const purchasPrice = await this.inputPurchaseModule.inputPurchaseAmount(); | ||
| const purchasQuantity = purchasPrice / 1000; |
There was a problem hiding this comment.
로또 1장 단위가 1000원이라 이 부분은 상수처리해도 좋겠다는 생각이 듭니다 :)
| @@ -1 +1,67 @@ | |||
| # javascript-lotto-precourse | |||
|
|
|||
| | |||
There was a problem hiding this comment.
줄바꿈인가요? 그냥 띄어쓰기해도 줄바꿈이 되는 경우도 있고 저 같은 경우는 \n으로 사용하는데,
사용하시는 이유가 궁금합니다!
There was a problem hiding this comment.
위 아래 간격을 더 띄어놓고 문서형태로 볼 때 가독성을 더 높이기 위해서 사용했던 HTML 코드입니다.
잘 사용되지 않는 것이며 개인적인 만족감에 사용하였던 것입니다 ㅎㅎ
| purchaseNumber: '개를 구매했습니다.', | ||
| winningStatistics: '당첨 통계\n--- ', | ||
| matchedThree: '3개 일치 (5,000원) - ', | ||
| matchedFour: '4개 일치 (50,000원) - ', | ||
| matchedFive: '5개 일치 (1,500,000원) - ', | ||
| matchedFiveBonus: '5개 일치, 보너스 볼 일치 (30,000,000원) - ', | ||
| matchedSix: '6개 일치 (2,000,000,000원) - ', | ||
| printQuantity: '개', | ||
| totalReturn: '총 수익률은 ', | ||
| totalReturnPercentage: '% 입니다.', | ||
| }; |
There was a problem hiding this comment.
상수처리를 하는 이유가 유지보수와 가독성 때문이라고 알고 있는데,
문장 자체를 상수처리 하면 오히려 가독성이 떨어지지는 않을까? 개인적으로 생각이 듭니다.
차라리 '당첨 통계', '총 수익률'과 같은 단어들을 상수화 하면 어떨지? 생각이 드는데, 여기에 대한 보람님 생각도 궁금합니다!
신경썼던 부분
어려웠던 부분
개인적인 회고
기본적인 폴더 생성, 파일 생성, 템플릿 코딩에서 시간을 소비해서는 절대 안될 것 같습니다.
개인적으로 test 코드를 빠르게 직접 잘 작성하는 방법을 열심히 배우면서 구상중인데 매우 어려운 것 같습니다. 여기에서 시간을 단축 시키는 것이 가장 큰 문제인 것 같습니다.
완벽하지 않은 부분에 대해서 다른 브랜치에서 지속적으로 구현볼 것입니다.