-
Notifications
You must be signed in to change notification settings - Fork 234
[문자열 덧셈 계산기] 한만욱 미션 제출합니다. #245
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?
Changes from all commits
0b02115
100e4f2
0811d15
affdc13
7e295b1
66407c5
bafbdb0
dfa88c5
48a1ab8
9894e9a
f1d73e6
0d7919d
b3aba35
edeb954
8675344
953a6b1
13d5e5f
3c0be91
d7c9eda
c69a58b
5e7598b
979cd65
3e7b889
ce20c3f
8286f1e
a23f88b
123ea27
5691a8a
f4c7145
0434003
70bd6d4
cd1b854
24d2557
cfa41e4
2f8b73d
7725021
3ebf241
a40d618
796265e
c23a799
adfa885
d25d18e
636a1a0
42b88ca
ed29065
15fc699
1a9a935
15179a6
c1ee356
81af4f4
d4f6f13
94aa076
77b99ac
9e67442
88f66bf
91dbfac
52d4557
df765a8
7d28a80
03c0267
b66422a
3f482f9
30972ee
11a2cee
6c44eac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,57 @@ | ||
| # javascript-calculator-precourse | ||
| # javascript-calculator-precourse | ||
|
|
||
| # 문자열 덧셈 계산기 개발 | ||
|
|
||
| ## 1. 기능요구 사항 | ||
|
|
||
| -[X] 커스텀 구분자를 추출하는 기능 -[X] 구분자를 통해 입력받은 숫자를 파싱하는 기능 -[X] 파싱된 입력이 올바른지 확인하는 기능 -[X] 파싱된 입력을 더하는 기능 | ||
|
|
||
| - Model | ||
| - Parser : 구분자 | ||
| - Number : 입력받은 숫자 | ||
| - Extraction : 추출자 | ||
| - RandomMaker : 랜덤 제작기 | ||
|
|
||
| - View | ||
| - InputView : 입력 | ||
| - OutputView : 출력 | ||
|
|
||
| - Controller | ||
| - Calculator : 계산기 | ||
|
|
||
| ### - 입력 요구사항 | ||
|
|
||
| -[X] 구분자와 야수로 구성된 문자열 -[X] 구분자 : `,` `:` `//커스텀구분자\n` | ||
|
|
||
| #### - 추가사항 | ||
|
|
||
| -[X] 음수 입력시 ERROR 처리 | ||
|
|
||
| ### - 출력 요구사항 | ||
|
|
||
| -[X] "결과 : {int}" -[X] 잘못된 입력시 [ERROR]로 시작하는 메시지와 함께 종료 | ||
|
|
||
| ## 2. 프로그래밍 요구 사항 | ||
|
|
||
| -[X] 프로그래밍의 시작지점은 App.js의 run() 인가? -[X] package.json 파일을 변경하지 않았는가? -[X] 프로그램 종료시 process.exit()를 호출하지 않았는가? -[X] 자바스크립트 코드 컨벤션에 맞게 작성했는가? -[X] @woowacourse/mission-utils에서 제공하는 Console API를 사용해서 구현했는가? | ||
|
|
||
| ## 3. 도전 사항 | ||
|
|
||
| -[X] TDD 설계원칙 적용 -[X] 테스트 코드 랜덤 문자열 생성기 구현 -[X] MVC 패턴 적용하기 -[X] 객체지향 원칙 준수하기 -[X] AI 사용 없이 구현하기 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AI 사용 없이 구현에 성공하셨군요..!! 대단하십니다 ..👍🏻 |
||
|
|
||
| ## 4. 예상 실행 결과 | ||
|
|
||
| 실행 결과 예시 | ||
| 덧셈할 문자열을 입력해 주세요. | ||
| 1,2:3 | ||
| 결과 : 6 | ||
|
|
||
| ### 5. 추가사항 | ||
|
|
||
| - 연속된 구분자의 입력을 허용할것인가 - 미허용 | ||
| - 공백 입력을 허용할것인가 - 미허용 | ||
| - 소수점을 허용할것인가 - 미허용 | ||
| -> 소수점이 포함된경우 커스텀 구분자로 . 이 오면 허용할것인가 | ||
| - 커스텀 구분자 여러개를 허용할것 인가 ? - 허용 | ||
| - 커스텀 구분자가 중간에 나오는것을 허용할것인가? - 미 허용 | ||
| - 커스텀 구분자가 . 일때 .. 처리를 어케할것인지 - 미 허용 구분자는 한글자 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,10 @@ | ||
| import Controller from './controller/Controller.js'; | ||
|
|
||
| class App { | ||
| async run() {} | ||
| async run() { | ||
| const controller = new Controller(); | ||
| await controller.run(); | ||
| } | ||
| } | ||
|
|
||
| export default App; |
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 에러 코드를 하나 하나 자세히 적어주셔서 에러가 났을 때 어떤 에러인지 한 번에 알 수 있을 것 같아요! |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| export const ERROR_MESSAGE = { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 런타임에서 변하지 않을 에러 메시지라면
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 평소에 개발을 할때에는 object.freez가 필요가 없었어서 자주 사용을 안하다보니 안좋은 습관이 들은것 같습니다.. 이번기회에 object.freez에 대해서 조금더 알게되었는데 얕은불변성만 보장한다는 사실을 처음 알게되었습니다 감사합니다!! |
||
| NOT_MINUS: '[ERROR] 음수가 포함되어 있습니다.', | ||
| NOT_EMPTY: '[ERROR] 공백이 포함되어 있습니다.', | ||
| NOT_NUMBER: '[ERROR] 숫자가 아닌것이 포함되어 있습니다.', | ||
| DELIMITER_CONTINUOUS: '[ERROR] 연속된 구분자가 존재합니다.', | ||
| DELIMITER_EMPTY: '[ERROR] 구분자가 공백입니다.', | ||
| DELIMITER_HAS_WHITESPACE: '[ERROR] 구분자에 공백이 포함되어 있습니다.', | ||
| DELIMITER_HAS_NUMBER: '[ERROR] 구분자에 숫자가 포함되어 있습니다.', | ||
| DELIMITER_NOT_SINGLE_CHAR: '[ERROR] 구분자는 한 글자여야 합니다.', | ||
| NOT_INTEGER: '[ERROR] 소수가 포함되어 있습니다.', | ||
|
Comment on lines
+1
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NOT_MINUS나 NOT_NUMBER에 어떤 게 음수가 아니고 어떤 게 숫자가 아닌지 불분명한 것 같아서 에러 메시지는 어차피 상수이니 조금 더 구체적으로 명시가 되면 가독성이 더 좋아질 것 같아요 ㅎㅎ
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NOT_MINUS인데 막상 글자와 하는역할은 포함되어 있다고 느껴지네요 말씀감사합니다 |
||
| }; | ||
|
Comment on lines
+1
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이런식으로 객체로 묶어서 constants를 표현하는 것도 좋은 것 같아요! |
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 문자열이나 상수를 constant로 묶은 것은 많이 봤는데, regex 관련된 것들만 따로 모아둔 것이 신선한거 같아요.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. regex를 따로 모아두고 util 대신 constant로 쓴 이유를 여쭤보신것 맞나요 ? 고민이 되는게 지금은 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| export const REGEX_PATTERNS = { | ||
| CUSTOM_DELIMITER_EXTRACT: /\/\/(.*?)\\n/g, | ||
| CUSTOM_DELIMITER_DEFINITION: /\/\/.+?\\n/g, | ||
|
Comment on lines
+1
to
+3
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 코드라면 |
||
| REGEX_SPECIAL_CHARS: /[.*+?^${}()|[\]\\]/g, | ||
| WHITESPACE: /\s/, | ||
| DIGIT: /\d/, | ||
| }; | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 정규식을 한번에 묶어둘 생각은 못했는데, 정규식이 코드에서 반복되는 것을 막아 좋은 것 같네요! |
||
| export const RegexUtils = { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 간단한 함수들이라서 constant 안에 두신 것 같은데 이렇게 두는 것도 괜찮아 보이네요 |
||
| escapeRegexChars(str) { | ||
| return str.replace(REGEX_PATTERNS.REGEX_SPECIAL_CHARS, '\\$&'); | ||
| }, | ||
|
|
||
| createContinuousPattern(delimiter) { | ||
| return new RegExp(`${delimiter}{2,}`); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 문자열의 패턴을 관리하는 |
||
| }, | ||
|
|
||
| createSplitPattern(delimiters) { | ||
| return new RegExp(delimiters.join('|')); | ||
| }, | ||
|
|
||
| createCusomPattern(delimiter) { | ||
| return `//${delimiter}\\n`; | ||
| }, | ||
| }; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 다른 분들 코드를 참고해보니까 Extraction, Number, Parser를 Calculator class에서 다루시는 분들이 많더라고요! 개인적으로 Calculator에서 관리하는것도 괜찮아 보입니다!!
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 말씀주신 내용 전적으로 공감합니다 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import Extraction from '../service/model/Extraction.js'; | ||
| import Parser from '../service/model/Parser.js'; | ||
| import inputView from '../view/InputView.js'; | ||
| import outputView from '../view/OutputView.js'; | ||
| import Number from '../service/model/Number.js'; | ||
| import validate from '../service/validate/validate.js'; | ||
|
|
||
| export default class Controller { | ||
| constructor() { | ||
| this.extraction = new Extraction(); | ||
| this.parser = new Parser(); | ||
| } | ||
|
|
||
| async run() { | ||
| try { | ||
| const input = | ||
| await inputView.readLineMessage('덧셈할 문자열을 입력해 주세요.'); | ||
|
Comment on lines
+16
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 에러메세지에 대해 상수로 분리하신 것을 보았습니다.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 지적 해주셔서 알게되었ㄴ네요... |
||
|
|
||
| // 구분자 추출 {raw:원본,escaped:정규식 이스케이프} | ||
| const { raw, escaped } = this.extraction.extractCustomDelimiters(input); | ||
| validate.validateDelimiters(raw); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 예외 처리를 따로 빼서 확실히 분리하신 것이 좋아보입니다! |
||
|
|
||
| const textWithoutDefinitions = | ||
| this.parser.removeCustomDelimiterDefinitions(input, raw); | ||
| validate.validateContinuousDelimiters(textWithoutDefinitions, escaped); | ||
|
Comment on lines
+23
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 변수명이 자세해서 특별한 주석 없이도 가독성이 좋은 것 같아요! 👀 |
||
|
|
||
| const numbers = this.parser.parseToNumbers( | ||
| textWithoutDefinitions, | ||
| escaped, | ||
| ); | ||
| validate.validateNumbers(numbers); | ||
|
|
||
| const numberModel = new Number(numbers); | ||
| await outputView.printMessage(`결과 : ${numberModel.getAddedNumbers()}`); | ||
| } catch (error) { | ||
| await outputView.printMessage(error.message); | ||
| throw new Error(error.message); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { REGEX_PATTERNS, RegexUtils } from '../../constant/regex.js'; | ||
|
|
||
| export default class Extraction { | ||
| extractCustomDelimiters(text) { | ||
| const delimiters = Array.from( | ||
| text.matchAll(REGEX_PATTERNS.CUSTOM_DELIMITER_EXTRACT), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. matchAll과 Array.from을 함께 사용하는 이유를 명확히 알고 싶습니다!
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 저도 처음에는 match를 사용했었는데 |
||
| (match) => match[1], | ||
| ); | ||
| return { | ||
| raw: delimiters, | ||
| escaped: this.#escapeDelimiters(delimiters), | ||
| }; | ||
| } | ||
|
|
||
| #escapeDelimiters(delimiters) { | ||
manNomi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return delimiters.map((delimiter) => | ||
| RegexUtils.escapeRegexChars(delimiter), | ||
| ); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| export default class Number { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 리뷰하다가 validate.js에서 js 내장 객체인 Number()를 사용하시는데
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 저도 사용하다 보니 계속 Number가 겹치더라고요 |
||
| #numbers; | ||
|
|
||
| constructor(numbers) { | ||
| this.#numbers = numbers; | ||
| } | ||
|
|
||
| getAddedNumbers() { | ||
| return this.#numbers.reduce((acc, cur) => acc + cur); | ||
| } | ||
|
Comment on lines
+8
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 빈 문자열 입력 등으로 숫자 배열이 비어질 수 있는데
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 헉 그러네요!! 초기값 지정을 했어야 했는데 감사합니다 ! |
||
| } | ||
|
Comment on lines
+1
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Number는 자바스크립트의 내장 객체 이름이라 혼동을 줄 수 있을 것 같습니다. 클래스명을 변경하거나, 단순한 기능이라면 별도 함수로 분리하는 것도 좋을 것 같습니다! |
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 전체적으로 함수와 class를 굉장히 잘 활용하신다고 느꼈습니다. 저도 다음엔 기능 별로 나눠보도록 해봐야 겠어요. 많이 배우고 갑니다!
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이해하고 쓰는거랑 알고 쓰는것의 차이를 많이 느끼고 있습니다.. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import { RegexUtils } from '../../constant/regex.js'; | ||
|
|
||
| const DEFAULT_DELIMITERS = [',', ':']; | ||
|
|
||
manNomi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| export default class Parser { | ||
| parseToNumbers(text, escapedDelimiters) { | ||
| const allDelimiters = [...escapedDelimiters, ...DEFAULT_DELIMITERS]; | ||
| const splitPattern = RegexUtils.createSplitPattern(allDelimiters); | ||
| return text | ||
| .split(splitPattern) | ||
| .filter((value) => value !== '') | ||
| .map((value) => Number(value)); | ||
| } | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 메서드 체이닝 때문에 코드가 길어지면 가독성이 떨어질 수 있을 것 같아요!
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 메소드 체이닝 때문에 코드가 읽히기 ㅅ쉽지 않다는것을 저도 느끼고 있습니다.. 과도한 분리 어떨때는 너무 심한 체이닝 저 자신을 돌아보게 되네요 좋은 글 공유해주셔서 감사합니다 ! |
||
| removeCustomDelimiterDefinitions(text, delimiters) { | ||
| let result = text; | ||
|
|
||
| delimiters.forEach((delimiter) => { | ||
| const definition = RegexUtils.createCusomPattern(delimiter); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 여기 부분 진짜 사소하긴 한데 createCustomPattern() 함수 오타 있는 것 같아서 리뷰 남깁니다..!
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 자바스크립트라 오타에 치명적일텐데!!! |
||
| if (result.startsWith(definition)) { | ||
| result = result.slice(definition.length); | ||
| } | ||
| }); | ||
|
|
||
| return result; | ||
| } | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 예외처리 함수가 많지 않기 때문에, 객체로 묶지 않고 각각 export 하는것도 괜찮아 보입니다!
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 너무 타당한 말씀이네요 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| import { ERROR_MESSAGE } from '../../constant/error.js'; | ||
| import { REGEX_PATTERNS, RegexUtils } from '../../constant/regex.js'; | ||
|
|
||
| const DEFAULT_DELIMITERS = [',', ':']; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 끝나고 코드리뷰를 받다보니 이런 실수들을 잡아주셔서 너무 좋네요 꼼꼼히 봐주셔 감사합니다 |
||
|
|
||
| const validate = { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 제가 모르는 것이 많아서 궁금한데 혹시 validate는 class로 만들지 않으신 이유가 있으신가요?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 조금 정곡을 찔린 것 같습니다. 저는 **“행위는 객체로 두지 않는다”**는 원칙을 가지고 있었지만, 실제로는 Parser, Extractor처럼 행위적인 로직도 객체로 만들었던 부분이 있어서 아쉬움이 남는 1주차였습니다. 일관성을 지키려면 validate 역시 클래스가 되어야 맞겠지요. 이 두 검증이 클래스 안팎에서 모두 사용될 수 있다면, 앞으로는 문법적 검증은 함수로, 도메인 검증은 클래스 내부 메서드로 분리하여 작성하려 합니다. |
||
| validateNumbers(numbers) { | ||
| numbers.forEach((number) => { | ||
| // 공백 체크 | ||
| if (typeof number === 'string' && number.trim() === '') { | ||
| throw new Error(ERROR_MESSAGE.NOT_EMPTY); | ||
| } | ||
| // 숫자 여부 체크 | ||
| if (Number.isNaN(Number(number))) { | ||
| throw new Error(ERROR_MESSAGE.NOT_NUMBER); | ||
| } | ||
| // 음수 체크 | ||
| if (number < 0) { | ||
| throw new Error(ERROR_MESSAGE.NOT_MINUS); | ||
| } | ||
| // 소수 체크 | ||
| if (!Number.isInteger(Number(number))) { | ||
| throw new Error(ERROR_MESSAGE.NOT_INTEGER); | ||
| } | ||
| }); | ||
|
Comment on lines
+7
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 여기서 Number(number)를 여러 번 호출하는 것 같습니다! 로 변환은 한번만 수행하고, 비교 연산은 num만 받아와서 하는 방향도 좋을 것 같아요!
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 꼼꼼하게 봐주셔서 정말감사합니다 |
||
| }, | ||
|
|
||
| validateContinuousDelimiters(inputText, escapedDelimiters) { | ||
| // 커스텀 구분자 정의 부분 제거 | ||
| const textToValidate = inputText.replace( | ||
| REGEX_PATTERNS.CUSTOM_DELIMITER_DEFINITION, | ||
| '', | ||
| ); | ||
|
Comment on lines
+30
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 와 저는 구분자 하나하나 비교를 수행했는데 모두 공백으로 바꾸는 방법이 있었네요! |
||
| const allDelimiters = [...DEFAULT_DELIMITERS, ...escapedDelimiters]; | ||
|
|
||
| allDelimiters.forEach((delimiter) => { | ||
| const escapedDelimiter = RegexUtils.escapeRegexChars(delimiter); | ||
| const continuousPattern = | ||
| RegexUtils.createContinuousPattern(escapedDelimiter); | ||
|
|
||
| if (continuousPattern.test(textToValidate)) { | ||
| throw new Error(ERROR_MESSAGE.DELIMITER_CONTINUOUS); | ||
| } | ||
|
Comment on lines
+41
to
+43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. const validate = { depth를 줄이기 위해서 forEach부분도 따로 함수로 뺄 수 있을 것 같고
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 말씀 감사합니다 이전주에 짠 코드임에도 잘 읽히지 않는것을 보니 |
||
| }); | ||
| }, | ||
|
|
||
| validateDelimiters(customDelimiters) { | ||
| customDelimiters.forEach((delimiter) => { | ||
| // 빈 값 체크 | ||
| if (!delimiter) { | ||
| throw new Error(ERROR_MESSAGE.DELIMITER_EMPTY); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 예외 처리에 대해 알아보다가 커스텀 에러 객체에 대해 알게 되었습니다.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Error 객체를 extends해서 쓰는것 너무 좋을 것 같은데요 ??? |
||
| } | ||
| // 공백 포함 체크 | ||
| if (REGEX_PATTERNS.WHITESPACE.test(delimiter)) { | ||
| throw new Error(ERROR_MESSAGE.DELIMITER_HAS_WHITESPACE); | ||
| } | ||
| // 숫자 포함 체크 | ||
| if (REGEX_PATTERNS.DIGIT.test(delimiter)) { | ||
| throw new Error(ERROR_MESSAGE.DELIMITER_HAS_NUMBER); | ||
| } | ||
| // 구분자가 한글자인지 체크 | ||
| if (delimiter.length !== 1) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 아주 사소한 부분이지만요..
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 너무 좋습니다! |
||
| throw new Error(ERROR_MESSAGE.DELIMITER_NOT_SINGLE_CHAR); | ||
| } | ||
| }); | ||
| }, | ||
| }; | ||
|
|
||
| export default validate; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import { Console } from '@woowacourse/mission-utils'; | ||
|
|
||
| const inputView = { | ||
| async readLineMessage(message) { | ||
| const input = await Console.readLineAsync(message); | ||
| return input; | ||
| }, | ||
| }; | ||
| export default inputView; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import { Console } from '@woowacourse/mission-utils'; | ||
|
|
||
| const outputView = { | ||
| async printMessage(message) { | ||
| await Console.print(message); | ||
| }, | ||
| }; | ||
| export default outputView; |
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.
도전사항 세세하게 작성하신거 진짜 대단하십니다...