-
Notifications
You must be signed in to change notification settings - Fork 232
[문자열 덧셈 계산기] 유인성 미션 제출합니다. #44
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?
Conversation
새로운 내용 추가 - 문제 정리 - 개발 - 목표
- Console.readLineAsync 문자 입력 구현 - 문자 입력 테스트 작성
- Console.print 결과 출력 구현 - 결과 출력 테스트 작성
- 문자 숫자 추출 메서드 구현 - 문자 숫자 추출 메서드 테스트 작성
- 숫자 더하기 매서드 구현 - 숫자 더하기 테스트 작성
- 결과 출력 메서드 테스트 코드 수정
- 문자 입력 메서드 테스트 코드 수정
- 문자열 검증 매서드 구현 - 문자열 검증 테스트 작성
- 계산기 메서드 구현 - 계산기 메서드 테스트 작성
- 메시지 출력 메서드 구현 - 메시지 출력 메서드 테스트 작성 - 문자열 검증 매서드 개선 - 오류 출력 -> 오류 유형 반환 역할 전환 - 문자열 검증 매서드 테스트 수정
- hasCustomDivision - 함수 모듈화 - 함수 테스트 작성 - 매서드 설명 주석 수정 - 메시지 출력 기능 - 개별 매서드 내부로 이동
- 숫자 검증 매서드 구현 - 숫자 검증 매서드 테스트 작성
- 숫자 판별 및 메시지 출력 매서드 적용 - 문자 입력 매서드 - 변수 오타 교정 - 메시지 출력 매서드 - 문자, 숫자 검증 테스트 분리 - 숫자 판별 매서드 - 오류 유형 대문자 적용
- 문자 숫자 추출 매서드 - replaceAll 적용하여 변환 문자 일괄 처리 - 숫자 더하기 매서드 - 합계가 문자열로 처리되어 숫자 타입 변환 재적용 - 개별 매서드 주석 재작성 - 변경 사항에 맞춰 테스트 코드 수정
- 계산기
- 계산 이후 반복 동작 적용
- this.run() 테스트 무한반복으로 주석 처리
- 'EMPTY_STRING' 예외처리 제외
- 결과가 2번 출력되는 문제 발생하며, 빈 문자열은 오류 던지지 않아도 됨
- 입력값이 undefined이면 빈 문자열로 처리하도록 readLineAsync 널 병합
연산자(??) 적용
- 테스트 코드 삭제 및 수정
- ApplicationTest 통과 확인
- 커스텀 구분자 검증 매서드 구현 및 적용 - 커스텀 구분자 검증 테스트 작성 - 메시지 출력 매서드, 오류 유형 추가 - 테스트 코드, extractNums 매서드 await 적용
- 메시지 출력 매서드, 유틸리티 함수로 전환 - throwMessage 함수 Console 의존성 주입 - 관련 테스트 코드 수정 - 관련 변수 이름 통일
- 사용자 입력, 구분자 검증, 숫자 배열 검증 함수 분리 - UtilityTesty.js -> UtilityTest.js 파일명 오탈자 수정 - "y" 삭제 - UtilityTest.js 테스트 코드 수정 및 테스트 함수명 가시화
- 구분자 추출, 구분자 부분 문자열 자르기로 세분화 - extractDivisionRegx, trimRespondPrefix 유틸 함수 작성 - 테스트 코드 작성 - hasCustomDivision 유틸 함수 반환값 수정 - 기본 구분자인 경우 'BASE' 반환 - 커스텀 문자열 확인 시 빈 문자열 오류 미반환 목적 - validateCustomDivision 유틸 함수 'BASE' 예외처리 추가
- 함수 주석 인자/반환 타입 및 예시 명시 - 반환값 타입은 예시 필요한 경우만 명시
- 구현 기능 목록 - '메시지 선택' 기능 제외 : 메시지 선택 기능은 메시지 출력 기능과 중복 - 예외 조건 - 기능 별 검증 조건 분류 및 재작성 - '공백' 조건 제외 : 빈 문자열과 공백 조건 동일해 '0' 반환 조건과 통합
- validateNums 함수 예외 사항 추가 - throwMessage 10 진수 판별 메시지 유형 추가 - 테스트 코드 - 관련 테스트 유형 추가 - 계산기 통합 테스트 실행 기준 성공/예외로 분류
- 성공/예외 테스트 케이스 추가 - 커스텀 구분자 '\' 일 때 테스트 실패 확인
- extractDivisionRegx, '\' 있는 경우 '\\'로 전부 치환 - new RegExp() 정규식 생성할 때 단일 '\' 인식 못해 오류 발생 - 유틸 테스트 케이스 추가
- 재사용 문자, 정규식 상수 파일로 분리 - 함수 인자 이름 변경해 가독성 개선
- 계산기 실행 시 출력되는 메시지 상수 처리 - 관련 테스트 코드 수정
- 변수명 수정
- division -> separator 변경
- division은 연산 관련 의미로 문자 구분을 의미하는 separator로 수정
- base -> default 변경
- 기본 설정값 의미 반영
- 기능 개선
- extractNums 매서드: replaceAll() 생략
- 메시지 상수화 및 문구 세분화
- hasCustomSeparator 조건 개선 - '//', '\n' 두 문자열 포함 여부 확인 - 테스트 케이스 추가
- 작업 일정 정리
- this.run() 삭제 - 성공 시 반복된다는 조건 명시되어 있지 않아 주석 코드 제외 - README 주의사항 수정
| { inputs: ['//q\\n1q2q3'], output: '결과 : 6' }, | ||
| { inputs: [' '], output: '결과 : 0' }, | ||
| { inputs: ['123'], output: '결과 : 123' }, | ||
| { inputs: ['+1,2'], output: '결과 : 3' }, |
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.
숫자 앞에 ㅇ
테스트케이스 'o1,2:3' 말씀하신 건가요??
glory-yun
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.
1주차 고생많으셨습니다!! 너무 잘하셔서 코멘트 남길게 별로 없었지만, 제 생각만 짧게 남겼으니 참고만 해주시면 될 것 같습니다!! 2주차도 화이팅입니다!!🔥🔥🔥
| const respond = await Console.readLineAsync(PROMPT_START_MESSAGE) ?? ''; | ||
|
|
||
| const hasMessage = validateInput(respond); | ||
| await throwMessage(hasMessage, Console); |
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.
extractNums , sum 함수 안에 있는 hasMessage 이랑 변수명이 겹쳐서 hasMessage 만으로는 어떤 에러 메시지인지 한번에 파악하기 힘든 것 같습니다! 물론 검증 함수를 통해서 유추 가능 하겠지만, 조금 더 직관적이면 좋을 것 같아요👍
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.
다시보니 hasMessage가 애매모호 하네요. 한 번 고민해봐야겠습니다.
| */ | ||
| export function trimRespondPrefix(respond, separator) { | ||
| if (separator === DEFAULT_SEPARATOR) return respond; | ||
| return respond.substring(2 + separator.length + 2); |
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.
만약 코드를 제대로 읽지 않으면, 숫자 '2'가 뭔지 다시 한번 생각할 수 있을 것 같습니다!
저도 이거를 어떻게 할지 고민 했는데, 상수로 따로 빼서 의미를 부여했습니다!!
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.
확실히 숫자 2보다 상수로 처리하는 게 나을 듯 하네요!
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.
이미 알고 계시겠지만, 역할 별로 분리해서 파일을 따로 만들면 가독성이 더 좋아질 것 같습니다!!!
kojesung
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.
1주차 과제 고생하셨습니다!! 코드리뷰가 조금 늦어졌네요 ㅎㅎ.. 죄송해요
인성님의 꼼꼼한 예외 처리 방식에 감명 받았습니다!! 저도 2주차 과제부터는 더 사용자 입장에서 제공받을 수 있는 더 자세한 에러를 반환하는 예외를 추가해봐야겠어요!
그리고 상수화해두는 방식도요!! 많이 배웠습니다
|
|
||
| if (!separator.trim()) return PASS; | ||
|
|
||
| const isNaN = Number.isNaN(Number(separator)); |
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.
인성님의 코드리뷰로 알게된 Number.isNaN 👍👍👍👍
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.
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.
제가 이해한 바에 따르면 현재 구조는
검증 함수 → 에러 타입 반환 → throwMessage로 전달 → switch 분기 처리 → print + throw 형식인데
함수에서 반환하는 에러를 바로 호출하지 않고 throwMessage를 통해 전달하고 switch 분기처리 후에 헨들링하는 이유가 궁금합니다.
함수에서 바로 처리한다면 throwMessage같이 콘솔 print와 에러 처리라는 2가지의 역할을 가지고 있는 함수가 불필요해지고 매번 Console을 인자로 전달해야하는 불편함도 사라지는 것을 기대할 수 있을 것 같습니다!
function validateNums(nums) {
nums.forEach(num => {
if (num < 0) {
throw new Error('[ERROR] 음수는 입력할 수 없습니다.');
}
});
}
검증함수에서 바로 Error를 throw하고 App에서 출력하는 형식을 생각했습니다!(제 코드 리뷰 꼼꼼하게 해주셔서 이미 아시겠지만 ㅎㅎ)
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.
저도 처음에 한 번에 포함해서 구현했어요 하핳
리팩토링할 때 어떻게 하면 역할을 분리할 수 있을까 고민하다 지금 구조가 되었네요.
throwMessage는 throw new Error() 부분이 공통적으로 중복돼서 하나로 처리해보자 해서 지금 모습이 되었어요.
오류 타입 반환은 기본 구분자, 커스텀 구분자 구분에 따라서 검증을 구분했는데 공통으로 처리하면 검증 기능이 무거워지더라고요. 그래서 구분자에 따라서 두 개의 검증 기능을 만들고 검증 조건이 겹쳐도 어떤 구분자에서 오류가 발생했는지 자세하게 알릴 수 있도록 했어요.
throwMessage 기능도 기본, 커스텀 구분자 오류 메시지 알림 두 부분으로 나눌 수 있었는데 하나로 묶은 또 다른 이유는 유지 보수 할 때, 어떤 오류 유형이 있는지 한 눈에 보려고 나누지 않았어요.
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.
Console.print는 async-await가 불필요한 것으로 알고있는데 이렇게 swtich문으로 관리할 때 필요한 것인지 궁금합니다!
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.
앗, 제출하고서 알았네요.
print는 동기였습니다.. await는 붙이지 않아도 되네요..
| * @returns {string} 오류 메시지 유형 | ||
| */ | ||
| export function validateInput(input) { | ||
| input = input?.trim() ?? ''; |
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.
trim 사용에 대해서 저도 고민했었는데 처음에는 편의를 위해 넣어두었다가 이후에는 제거하였습니다. 그 이유는
- 사용자가 입력한 값에 대한 정확한 응답을 얻을 수 없음
- validate는 검증의 역할인데 변환의 작업까지 하고 있어서 혼동을 줄 수 있음
이었는데요! 이러한 관점에서 인성님의 의견도 궁금합니다!!
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.
음.. 검증 내부에서 사용하는데 다른 곳 말고 여기서 적용하는게 낫지 않나 생각했어요.
trim()을 적용하지 않아도 숫자 검증에서 오류를 반환해서 계산기가 멈추는데 입력에서 잡을 수 있는 오류를 숫자 검증 단계까지 내려가서 잡는 게 연산 부분에서 비효율적이라고 생각했어요. 그래서 입력 검증에서 잡을 수 있는 오류는 다 잡아보자 했고 trim()을 적용하게 되었네요.
HarrySeop
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.
인성님! 코드리뷰 해주셔서 저도 하러왔습니다! 일정이 바빴어서 너무 늦게 남겨서 죄송합니다ㅠㅠ
구현은 잘 하신 것 같아서 궁금한 점을 남겨봤습니다! 시간 괜찮으실때 확인 부탁드려요!
+) 추가로 제 리뷰에 남긴 것에 대해서 답변을 드리자면 아직까지는 미션 자체의 라인수가 많지 않아서 파일 분리는 불필요한 과정이라고 생각해서 하지 않았습니다 (확실하게 못 나눈 것도 있지만 변명입니다..ㅎ)
| async run() { | ||
| try { | ||
| await this.calculator(); | ||
| } catch (err) { | ||
| throw Error(err); | ||
| } | ||
| } |
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.
try-catch문을 사용한 이유는 저희가 정의한 예외 케이스 이외의 에러가 나타날 수 있다는 가정이였는지 궁금합니다.
위 이유가 맞다면 err로 처리하는 것 보단 [ERROR] 예기치 못한 에러가 발생했습니다. 같은 유저친화적 메세지로 에러를 처리해도 좋을 것 같아요!
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.
아, 이 부분은 계산기 반복 실행 하려고 try-catch 문으로 감싸놓은 건데 단일 실행으로 바꿀 때 try-catch문을 제거하는 걸 깜박했네요 하핳
| * @returns {Promise<string>} "1,2:3" "//q\n1q2" | ||
| */ | ||
| async readLine() { | ||
| const respond = await Console.readLineAsync(PROMPT_START_MESSAGE) ?? ''; |
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.
해당 respond에서 ?? '' 부분은 무슨 이유로 하신것인지 궁금해요! 방어코딩 목적이였는지 궁금합니다!
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.
예외 테스트할 때 입력값이 undefined로 할당돼서 오류 해결하기 위해서 빈 문자열로 설정했습니다!
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.
Console.print는 async-await가 불필요한 것으로 알고있는데 이렇게 swtich문으로 관리할 때 필요한 것인지 궁금합니다!
whitecity01
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.
안녕하세요 예상보다 늦게 리뷰하게 돼서 죄송합니다 ㅠㅠ
다른 분들이 너무 좋은 리뷰를 남겨 주신 것 같아서 저는 제가 배운 점을 위주로 리뷰했습니다.
너무 수고하셨고 2주 차도 같이 화이팅 해 보아요!
| /** | ||
| * 문자 숫자 추출 | ||
| * @param {string} respond | ||
| * @returns {Promise<string[]>} ['1', '1', '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.
각 함수의 param과 returns를 주석처리 해놓는게 너무 깔끔하고 이해하기 쉽네요!
한 수 배웠습니다!
| async calculator() { | ||
| const respond = await this.readLine(); | ||
|
|
||
| const nums = await this.extractNums(respond); | ||
|
|
||
| const result = await this.sum(nums); | ||
|
|
||
| await this.print(result); | ||
| } |
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.
입력, 추출, 연산, 출력 과정이 명확하게 보여서 좋은 것 같습니다. 깔끔하네요!
| const nums = await this.extractNums(respond); | ||
|
|
||
| const result = await this.sum(nums); | ||
|
|
||
| await this.print(result); |
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.
respond 말고는 비동기 처리 할 필요 없지 않나요?
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.
this.print는 await를 안 붙여도 되는데 붙였네요..
this.sum은 내부에서 비동기 함수를 호출하고 있어서 await를 붙였습니다.
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.
저도 앞 리뷰어님들과 같은 생각입니다! print는 비동기가 불필요할 것 같아요 :)
| const hasNegative = nums.some((num) => Math.sign(num) === -1); | ||
| if (hasNegative) return NOT_ALLOWED_NEGATIVE; | ||
|
|
||
| const hasNaN = nums.some((num) => Number.isNaN(num)); | ||
| if (hasNaN) return NOT_ALLOWED_NAN; | ||
|
|
||
| const isInteger = nums.every((num) => Number.isInteger(num)); | ||
| if (!isInteger) return ONLY_ENTER_INTEGER; |
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.
저는 for 루프로 일일이 true/false를 검증했었는데 some과 every라는 메서드를 리뷰하면서 처음 알게 되었습니다.
js 내장 메서드를 활용하니 코드가 너무 간결하고 깔끔해지는 것 같네요!
Jinoko01
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.
앞으로 남은 과제도 화이팅 !
| export const ERROR_MESSAGE = { | ||
| NOT_END_WITH_SEPARATOR: ERROR_PREFIX + '입력은 반드시 숫자로 끝나야 합니다.', | ||
| NOT_ALLOWED_NEGATIVE: ERROR_PREFIX + '음수는 계산할 수 없습니다.', | ||
| NOT_ALLOWED_NAN: ERROR_PREFIX + '입력값을 다시 확인해주세요.', | ||
| ONLY_ENTER_INTEGER: ERROR_PREFIX + '숫자는 정수로만 입력해야 합니다.', | ||
| CUSTOM_SEPARATOR_EMPTY: ERROR_PREFIX + '커스텀 구분자가 비어 있습니다.', | ||
| CUSTOM_SEPARATOR_NOT_ALLOWED_NUMBER: ERROR_PREFIX + '커스텀 구분자는 숫자가 될 수 없습니다.', | ||
| ONLY_ALLOWED_DECIMAL: ERROR_PREFIX + '숫자는 10진수로 입력해야 합니다.', | ||
| }; |
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.
ERROR_PREFIX와 에러 메시지를 더한 문자열을 만들 때는 템플릿 리터럴을 사용하는 구조가 더 좋아보여요. Airbnb 코드 컨벤션에서도 권장하는 것 같습니다. https://github.com/airbnb/javascript?tab=readme-ov-file#strings
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.
1주차 정말 고생 많으셨습니다! 🙌
리뷰가 조금 늦어서 죄송해요 ㅠㅠ 🥹
테스트 코드를 꼼꼼하게 작성해주셔서 다음 주차 미션 테스트 작성에 많은 도움이 될 것 같아요 😊
또한 유효성 검사 로직도 체계적으로 구현되어 있어 읽기 편하고 안정적인 코드였습니다.
다음 주차도 화이팅입니다! 💪
| const separator = hasCustomSeparator(respond); | ||
|
|
||
| const hasMessage = validateCustomSeparator(separator); | ||
| await throwMessage(hasMessage, Console); |
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.
현재 throwMessage를 await으로 호출하고 있는데, 이 함수가 단순히 throw new Error() 형태라면 await는 불필요한 것 같아요! throwMessage가 내부에서 Console.print() 후 throw 한다면 괜찮지만, 그렇지 않다면 비동기 구조를 유지할 필요는 없는 것 같습니다.
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.
print 메서드가 비동기인줄 알고 잘못 붙였네요.. 말씀하신대로 비동기 처리하지 않아도 될 것 같아요!
| * @returns {Promise<number>} | ||
| */ | ||
| async sum(nums) { | ||
| const hasMessage = validateNums(nums); |
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.
hasMessage라는 변수명이 boolean 값처럼 느껴지는데 실제론 에러 메시지 문자열이네요! 좀 더 명확하게 바꾸면 좋을 것 같습니다.😊
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.
hasMessage가 메시지 내용을 가지고 있다는 의미를 나타내고 싶었는데 다시 한 번 생각해봐야겠군요.
| const hasMessage = validateNums(nums); | ||
| await throwMessage(hasMessage, Console); | ||
|
|
||
| return nums.reduce((acc, cur) => acc + Number(cur), 0); |
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.
만약 cur이 빈 문자열('')이 들어오면 Number('') === 0으로 판단되어서 의도치 않은 결과를 줄 수 있을 것 같아요🙂
return nums.reduce((acc, cur) => acc + (Number(cur) || 0), 0);
이런 식으로 validateNums에서 이미 처리하더라도, 안전하게 한 번 더 보정하는 게 좋을 것 같습니다 :)
아니면, validateNums 단계에서 빈 문자열을 아예 막는 게 더 좋은 것 같아요!
| const nums = await this.extractNums(respond); | ||
|
|
||
| const result = await this.sum(nums); | ||
|
|
||
| await this.print(result); |
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.
저도 앞 리뷰어님들과 같은 생각입니다! print는 비동기가 불필요할 것 같아요 :)
|
코드 리뷰가 늦어져 죄송합니다 🥹 테스트 코드를 각 예외 상황에 맞게 구체적으로 작성하신 부분이 좋은 것 같습니다! 이번 주차도 고생 많으셨고, 남은 프리코스 기간도 파이팅입니다 :) |
javascript-calculator-precourse
프리코스 1주차 일정 (25.10.14 ~ 25.10.20)
문제 정리
입력한 문자열에서 구분자 통해 추출한 숫자를 더하는 계산기다.
잘못된 문자열을 입력하면 메시지가 전달되는 동시에 오류를 발생시켜 프로그램을 종료시킨다.
구분자
기본 구분자
쉼표 또는 콜론
예시
커스텀 구분자
"//" 와 "/n" 사이 위치하는 문자
예시
메시지
메시지는 "[ERROR]"로 시작한다.
조건
사용자가 잘못된 값을 입력하는 경우 메시지를 전달한다.
추가기능
메시지가 출력되면
Error도 함께 발생하며 프로그램을 종료시킨다.입력
구분자와 양수로 구성된 문자열이다.
개발
더하기 계산기 흐름
올비른 문장인 경우
올바르지 않은 문장인 경우
구현 기능 목록
문자 입력문자열 검증메시지 출력문자서 숫자 추출숫자 더하기숫자 출력예외 조건
예외조건은 계속 추가한다.
사용자 입력 문장 검증
커스텀 구분자 검증
구분자가 존재하지 않는 경우
구분자가 숫자인 경우
문자형 숫자 배열 검증
10진수가 아닌 경우
음수가 포함되어 있는 경우
NaN가 포함되어 있는 경우
모든 숫자가 정수가 아닌 경우
주의사항
사용자가 잘못된 값을 입력해야 프로그램이 종료된다.
구현 우선으로 예외 사항 때문에 구현이 늦어지지 않도록 한다.
계산 성공 시 반복되어야 하는 조건 명시되어 있지 않아 반복 실행하지 않는다.
목표
Class로 구현한다.기능개발되면 로컬 테스트 통과한 다음에 커밋한다.예외사항이 추가되어도 다른 코드가 영향 받지 않도록 한다.