[문자열 덧셈 계산기] 김예림 미션 제출합니다.#222
Open
yerimming wants to merge 19 commits intowoowacourse-precourse:mainfrom
Open
[문자열 덧셈 계산기] 김예림 미션 제출합니다.#222yerimming wants to merge 19 commits intowoowacourse-precourse:mainfrom
yerimming wants to merge 19 commits intowoowacourse-precourse:mainfrom
Conversation
…연결 구현 - ConsoleView 인스턴스 생성 및 run 메서드 추가 - 사용자 입력을 비동기적으로 처리하는 구조 설정
- ,과 :를 구분자로 사용해 문자열을 구분해 배열로 저장
- 기존 splitByDefaultSeperator를 parseInt으로 통합 - getCustomSeperator 메서드에서 커스텀 구분자를 추출 - 기본 구분자(, :)와 커스텀 구분자를 모두 처리하도록 splitNumbers 메서드 구현
- 입력받은 문자열을 parseInt 메서드로 전달해 구분자를 기준으로 문자를 구분
- 구분한 값이 숫자가 아니거나 0 이하인 경우 에러 발생 후 애플리케이션 종료
- readLineAsync 호출 시 try-catch로 에러 처리 추가
- 입력 문자열 파싱 후 숫자 배열 생성 - 숫자 유효성 검사 기능 추가 - 숫자 합산 후 결과 출력 - try-catch로 예외 처리하여 오류 발생 시 에러 메시지 출력
iftype
reviewed
Oct 22, 2025
| let numbersPart = input; | ||
| const customSeperator = this.getCustomSeperator(input); | ||
|
|
||
| if(customSeperator) { |
There was a problem hiding this comment.
//let numbersPart = input; 삭제
const customSeperator = this.getCustomSeperator(input);
if (customSeperator) {
const numbersPart = input.split(`\\n`)[1];
return this.splitNumbers(numbersPart, customSeperator);
}
//... 이 경우 early return 을 사용하면 const로 바꿀 수 있어보입니다!
| }); | ||
| } | ||
|
|
||
| sum(numbers) { |
There was a problem hiding this comment.
import { sum } from "./utils.js";
export function sum(numbers){
//...
}인스턴스를 사용하지 않는 간단한 함수는 유틸폴더로 빼서 클래스의 크기를 줄이는 방법도 있습니다!
| validateNumbers(numbers) { | ||
| numbers.forEach((value) => { | ||
| const num = Number(value); | ||
| if(isNaN(num) || num < 0) { |
There was a problem hiding this comment.
Number.isNaN 을 권장하고있습니다!
MDN Number.isNaN()
velog-isNan()
|
|
||
| class CalculatorController { | ||
| constructor() { | ||
| this.view = new ConsoleView(); |
There was a problem hiding this comment.
// 정적메소드로 변경 시
// controller/CalculatorController.js
import ConsoleView from "../view/ConsoleView.js";
// this.view = new ConsoleView(); 제거
// ...
ConsoleView.printResult(result);// view/ConsoleView.js
class ConsoleView {
static printResult() {
//...
}
}ConsoleView 클래스의 메소드들은 인스턴스 상태를 사용할 필요가 없어보여서
static method 로 만들어서 호출하는게 좋아보입니다..!
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.
No description provided.