-
Notifications
You must be signed in to change notification settings - Fork 4
yxxndxxn 1주차 문자열 계산 #1
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
고생하셨습니당 |
const customDelimiter = (input) => { | ||
if (input.startsWith("//")) { | ||
const endDelimiter = input.indexOf("\\n"); //마지막 찾기 | ||
if (endDelimiter == -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.
endDelimeter 가 -1일때 올바른 커스텀 구분자 형식이 되도록 한 논리가 무엇인가요?
@@ -1,5 +1,18 @@ | |||
import { Console } from "@woowacourse/mission-utils"; | |||
import Calculator from "./Calculator.js"; |
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.
Calculator 라이브러리 쓰신 이유가 궁금합니다..!!저는 Console 외의 라이브러리 없이 구현해서요..!!
const add = (input) => { | ||
if (!input) return 0; | ||
|
||
const numbers = splitDelimiter(input).map(validateNumber); |
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.
코드 가독성이 좋은 것 같아요! 기능별로 나누어져있어서 읽기가 수월했던 것 같습니다. 수고하셨습니다!
throw new Error("양수가 아닙니다."); | ||
} | ||
return parsed; | ||
}; |
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.
숫자가 아닐 때도 양수가 아닐 때도 오류 메시지를 보낼 거니까, or을 사용해서 한 번에 묶으면 좀 더 간결하게 나타낼 수 있을 것 같습니다!
//기본 구분자 | ||
return numbers.split(/[,:]/).filter((num) => num !== ""); | ||
} | ||
}; |
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.
만약 둘 다 사용하려면
else를 사용하는 대신
21행으로 return한 값을 기본 구분자로 다시 구분해보는 방식을 쓰면 되겠네요
@@ -0,0 +1,47 @@ | |||
export default function Calculator() { |
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.
파일 분리를 하셔서 코드가 깔끔한 것 같아요
전 App하나로 다 해결하려다 보니 가독성이 조금 떨어졌는데
잘 보고 참고하겠습니다
- [x] 입출력 기능 구현 | ||
- [x] 기본 구분자(쉼표, 콜론)로 입력된 경우 계산 | ||
- [x] 커스텀 구분자로 입력된 경우 계산 | ||
- [x] 예외 처리 |
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.
고려하신 예외가
- 커스텀 구분자 지정 형식 //@\n
- NaN
- 음수
등이 있으신거 같아요
저는 소수점 계산도 실행해보고 싶어서 .을 커스텀 구분자로 지정하지 못하게 했는데
혹시 추가로 고려하신 예외가 더 있으신가요?
No description provided.