-
Notifications
You must be signed in to change notification settings - Fork 232
[문자열 덧셈 계산기] 김예림 미션 제출합니다. #222
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
…연결 구현 - ConsoleView 인스턴스 생성 및 run 메서드 추가 - 사용자 입력을 비동기적으로 처리하는 구조 설정
- ,과 :를 구분자로 사용해 문자열을 구분해 배열로 저장
- 기존 splitByDefaultSeperator를 parseInt으로 통합 - getCustomSeperator 메서드에서 커스텀 구분자를 추출 - 기본 구분자(, :)와 커스텀 구분자를 모두 처리하도록 splitNumbers 메서드 구현
- 입력받은 문자열을 parseInt 메서드로 전달해 구분자를 기준으로 문자를 구분
- 구분한 값이 숫자가 아니거나 0 이하인 경우 에러 발생 후 애플리케이션 종료
- readLineAsync 호출 시 try-catch로 에러 처리 추가
- 입력 문자열 파싱 후 숫자 배열 생성 - 숫자 유효성 검사 기능 추가 - 숫자 합산 후 결과 출력 - try-catch로 예외 처리하여 오류 발생 시 에러 메시지 출력
iftype
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.
코멘트 편집하다 실수해서 다시 씁니다..
잘보고갑니다
| let numbersPart = input; | ||
| const customSeperator = this.getCustomSeperator(input); | ||
|
|
||
| if(customSeperator) { |
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.
//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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Number.isNaN 을 권장하고있습니다!
MDN Number.isNaN()
velog-isNan()
|
|
||
| class CalculatorController { | ||
| constructor() { | ||
| this.view = new ConsoleView(); |
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.
// 정적메소드로 변경 시
// 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 로 만들어서 호출하는게 좋아보입니다..!
No description provided.