-
Notifications
You must be signed in to change notification settings - Fork 9
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
[문자열 덧셈 계산기] 이나영 미션 제출합니다. #572
base: main
Are you sure you want to change the base?
Changes from 1 commit
6f0da34
f2f9c42
d2b9264
fe7259c
249df5a
316cc8f
e1020e0
7dabd65
7abe52f
4ed98a0
f526e61
c2100f7
a36fc48
614215e
08968bb
3b9b3f9
a87d260
8068e41
ca88274
41788bd
bc4ca74
865940c
1560c40
62aec6b
ed58de9
ebb788a
acf275e
6975470
5578dc8
a32249e
fc27c21
7127a59
8db452d
540ce83
593ae60
a651bc2
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
export default [ | ||
{ | ||
files: ["**/*.js"], | ||
languageOptions: { | ||
ecmaVersion: 2021, | ||
sourceType: "module" | ||
}, | ||
rules: { | ||
"quotes": ["error", "single"], | ||
"object-curly-spacing": ["error", "always"], | ||
"indent": ["error", 2], | ||
"max-len": ["error", { "code": 100 }], | ||
"wrap-iife": ["error", "outside"], | ||
"newline-before-return": "error", | ||
"no-mixed-spaces-and-tabs": ["error", "smart-tabs"] | ||
} | ||
} | ||
]; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,13 +2,11 @@ import { parseInput } from './addFuntions/parseInput.js'; | |
import { validateNumber } from './addFuntions/validateNumber.js'; | ||
|
||
export function add(input) { | ||
if (input === "") return 0; | ||
|
||
if (input === '') return 0; | ||
const { numbers, delimiter } = parseInput(input); // 입력 파싱 | ||
|
||
const parsedNumbers = numbers | ||
.split(delimiter) | ||
.filter(num => num !== "") // 중복된 구분자 처리 | ||
.filter(num => num !== '') // 중복된 구분자 처리 | ||
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. 여러개의 구분자가 있다는 케이스는 생각을 못했었는데 배워갑니다 ㅎㅎ |
||
.map(validateNumber); // 숫자 유효성 검증 및 변환 | ||
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. 로직 깔끔해용~ 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. add 함수에 너무 많은 역할이 있는 것 말씀이시죠 ? 다음 미션에서는 단일 책임의원칙에 대해 더 공부하고 코딩하려구요 !! 좋은 지적 너무 감사드려요 🍀 |
||
|
||
return parsedNumbers.reduce((sum, num) => sum + num, 0); // 합산 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,10 +2,10 @@ | |
export function parseInput(input) { | ||
let delimiter = /[,|:]/; // 기본 구분자 | ||
|
||
if (input.startsWith("//")) { | ||
const parts = input.split("\\n"); | ||
if (input.startsWith('//')) { | ||
const parts = input.split('\\n'); | ||
|
||
if (parts.length < 2 || parts[1].trim() === "") { | ||
if (parts.length < 2 || parts[1].trim() === '') { | ||
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. 저는 정규표현식을 사용하지 않고 문제 해결하기 까다롭다고 생각했는데, 이런 식으로 접근할 수도 있군요! 많이 배워갑니다. 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] 잘못된 입력 형식입니다.'); | ||
} | ||
|
||
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. 구분자를 판별하는 과정에서 정규표현식을 사용해보면 어떨까요? 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. 맞네요 그럼 저 부분이 좀 더 깔끔해질 것 같아요 !! 조언 감사드려요 ! 👍 |
||
|
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.
add라는 함수에 input을 parse하고 그것들을 split해서 더하는 것도 진행되고 있는 것 같은데, 한 함수에 add만 하는 것이 아니라 다른 기능도 여러 개 들어간 것 같습니다. 단일 책임 원칙으로 함수를 더 쪼개서 함수에 대한 직관성을 높이면 어떨까 생각이 듭니다!
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주차 미션에서는 신경써야겠어요. 조언 너무 감사드립니다 !!