Skip to content
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

Open
wants to merge 36 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
6f0da34
docs: README 문구 추가
Bewheneverwhatiwant Oct 17, 2024
f2f9c42
docs: REACME 내용 보완 - branch 전략 추가
Bewheneverwhatiwant Oct 17, 2024
d2b9264
docs: README 브랜치 전략 수정
Bewheneverwhatiwant Oct 18, 2024
fe7259c
feat: 빈 문자열 입력 시 0 반환 기능 추가
Bewheneverwhatiwant Oct 20, 2024
249df5a
docs: README 내용 추가 - 이슈 자동닫힘->수동닫음으로 전략 변경
Bewheneverwhatiwant Oct 20, 2024
316cc8f
feat: 쉼표구분자 문자열 입력 시 연산 기능 추가
Bewheneverwhatiwant Oct 20, 2024
e1020e0
docs: README 일부 내용 삭제
Bewheneverwhatiwant Oct 20, 2024
7dabd65
docs: README 개행 수정
Bewheneverwhatiwant Oct 20, 2024
7abe52f
feat: 쉼표 또는 콜론 구분자의 문자열 입력 시 연산 기능 추가
Bewheneverwhatiwant Oct 20, 2024
4ed98a0
feat: 커스텀 구분자 지원 기능 추가
Bewheneverwhatiwant Oct 20, 2024
f526e61
feat: 음수, 숫자가 아닌 값, 잘못된입력 처리 기능 추가
Bewheneverwhatiwant Oct 20, 2024
c2100f7
docs: README에 사용자 입력 겨우의 수 내용 추가
Bewheneverwhatiwant Oct 20, 2024
a36fc48
docs: README 개행 분리
Bewheneverwhatiwant Oct 20, 2024
614215e
refactor: run() 내부 try catch로 수정, 컨벤션에 따른 수정
Bewheneverwhatiwant Oct 20, 2024
08968bb
feat: 커스텀 구분자와 기본 구분자를 혼용해도 연산 가능하도록 기능 추가
Bewheneverwhatiwant Oct 20, 2024
3b9b3f9
docs: README 기능 및 사용자 경우의 수 추가
Bewheneverwhatiwant Oct 20, 2024
a87d260
chore(ApplicationTest): 테스트케이스(쉼표 구분자)추가
Bewheneverwhatiwant Oct 20, 2024
8068e41
chore(ApplicationTest): 테스트케이스(zhffhs rnqnswk) 추가
Bewheneverwhatiwant Oct 20, 2024
ca88274
chore(ApplicationTest): 테스트케이스(콜론 구분자) 추가
Bewheneverwhatiwant Oct 20, 2024
41788bd
Merge branch 'bewheneverwhatiwant' of https://github.com/Bewheneverwh…
Bewheneverwhatiwant Oct 20, 2024
bc4ca74
chore(ApplicationTest): 테스트케이스(커스텀 구분자만 입력하는 경우) 추가
Bewheneverwhatiwant Oct 20, 2024
865940c
chore(ApplicationTest): 테스트케이스(커스텀 구분자가 /,\,\n인 경우) 추가
Bewheneverwhatiwant Oct 20, 2024
1560c40
style: AirBnB 가이드에 맞춰 큰따옴표를 작은따옴표로 변경
Bewheneverwhatiwant Oct 20, 2024
62aec6b
style(App): AirBnB 가이드에 맞춰 큰따옴표를 작은따옴표로 변경
Bewheneverwhatiwant Oct 20, 2024
ed58de9
Merge branch 'bewheneverwhatiwant' of https://github.com/Bewheneverwh…
Bewheneverwhatiwant Oct 20, 2024
ebb788a
refactor(App): 3개의 함수들을 별도 파일로 분리
Bewheneverwhatiwant Oct 20, 2024
acf275e
refactor(all): 파일 구조를 폴더로 정리
Bewheneverwhatiwant Oct 20, 2024
6975470
refactor(add): 2개 함수를 별도 파일로 분리
Bewheneverwhatiwant Oct 20, 2024
5578dc8
docs(README): 프로그램 흐름을 정리한 내용 추가
Bewheneverwhatiwant Oct 20, 2024
a32249e
docs(README): 오타 및 개행 수정
Bewheneverwhatiwant Oct 20, 2024
fc27c21
docs(README): 디렉토리 구조 설명 추가
Bewheneverwhatiwant Oct 20, 2024
7127a59
docs(README): 개행 수정
Bewheneverwhatiwant Oct 20, 2024
8db452d
docs(README): 기능들의 상위 기능 정의
Bewheneverwhatiwant Oct 20, 2024
540ce83
docs(README): 개행 수정
Bewheneverwhatiwant Oct 20, 2024
593ae60
docs(README): 개행 수정
Bewheneverwhatiwant Oct 20, 2024
a651bc2
refactor(all): eslint.config.js 파일에 따른 eslint적용
Bewheneverwhatiwant Oct 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions eslint.config.js
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"]
}
}
];
6 changes: 2 additions & 4 deletions src/functions/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ import { parseInput } from './addFuntions/parseInput.js';
import { validateNumber } from './addFuntions/validateNumber.js';

export function add(input) {

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만 하는 것이 아니라 다른 기능도 여러 개 들어간 것 같습니다. 단일 책임 원칙으로 함수를 더 쪼개서 함수에 대한 직관성을 높이면 어떨까 생각이 듭니다!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

너무 좋은 피드백이네요 ! 제가 아직 초보라 입력/계산/출력 정도로만 나눠도 가독성이 좋지 않을까? 라는 막연한 생각을 가졌었는데, 단일 책임의 원칙에 대해서 공부하고 2주차 미션에서는 신경써야겠어요. 조언 너무 감사드립니다 !!

if (input === "") return 0;

if (input === '') return 0;
const { numbers, delimiter } = parseInput(input); // 입력 파싱

const parsedNumbers = numbers
.split(delimiter)
.filter(num => num !== "") // 중복된 구분자 처리
.filter(num => num !== '') // 중복된 구분자 처리

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여러개의 구분자가 있다는 케이스는 생각을 못했었는데 배워갑니다 ㅎㅎ

.map(validateNumber); // 숫자 유효성 검증 및 변환

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

로직 깔끔해용~
하지만 저도 함수를 조금 더 분리하면 좋을 것 같다는 생각입니다!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add 함수에 너무 많은 역할이 있는 것 말씀이시죠 ? 다음 미션에서는 단일 책임의원칙에 대해 더 공부하고 코딩하려구요 !! 좋은 지적 너무 감사드려요 🍀


return parsedNumbers.reduce((sum, num) => sum + num, 0); // 합산
Expand Down
6 changes: 3 additions & 3 deletions src/functions/addFuntions/parseInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() === '') {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저는 정규표현식을 사용하지 않고 문제 해결하기 까다롭다고 생각했는데, 이런 식으로 접근할 수도 있군요! 많이 배워갑니다.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

윗분께서 말씀주신대로 조건문이 좀 중첩되는 느낌이 있어서, 다음 미션에서는 더 깔끔하게 해보려구요 !! 칭찬 감사드립니다 👍

throw new Error('[ERROR] 잘못된 입력 형식입니다.');
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

구분자를 판별하는 과정에서 정규표현식을 사용해보면 어떨까요?
if 조건문을 중첩해서 사용하는 것보다 훨씬 간단하게 처리할 수 있다고 생각합니다

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

맞네요 그럼 저 부분이 좀 더 깔끔해질 것 같아요 !! 조언 감사드려요 ! 👍

Expand Down
1 change: 1 addition & 0 deletions src/functions/getInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ import { Console } from '@woowacourse/mission-utils';

export async function getInput() {
const input = await Console.readLineAsync('덧셈할 문자열을 입력해 주세요.\n');

return input;
}