Skip to content

[문자열 계산기] 이금주 미션 제출합니다.#3

Open
GeumZu wants to merge 3 commits into
Java-JavaScript-Language-Stuty:mainfrom
GeumZu:main
Open

[문자열 계산기] 이금주 미션 제출합니다.#3
GeumZu wants to merge 3 commits into
Java-JavaScript-Language-Stuty:mainfrom
GeumZu:main

Conversation

@GeumZu

@GeumZu GeumZu commented Feb 6, 2025

Copy link
Copy Markdown

1주차 미션 업로드

@GeumZu GeumZu changed the title 계산기 첫구현 [문자열 계산기] 이금주 미션 제출합니다. Feb 7, 2025
@ParkHyeonkyu

Copy link
Copy Markdown

고생하셨습니다
저도 부족하지만 열심히 리뷰해보겠습니다

@yuninam2128 yuninam2128 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

수고하셨습니다! 제가 완전 초보라서 질문만 적어두고 가네요..

Comment thread src/App.js
delimiter = new RergExp(customDelimeterMatch[1]);
input = customDelimeterMatch[2];
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

이 부분 잘 이해가 안 가서 혹시 설명해주실 수 있으신가요?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

match()는 자바스크립트에서 문자열(String) 객체에 내장된 메서드로 문자열 안에서 찾고자 하는 패턴을 정규 표현식을 이용해 검색하는 함수입니다. /^//(.)\n(.*)/ 의 정규 표현식에 매칭되도록 배열을 반환합니다. 위 코드에서 customDelimeterMatch[1] 은 Delimeter(예를 들면 ;)이 대입이 되어 있고 customDelimeterMatch[2]에는 사용자가 입력한 덧셈 식이 대입되어 있습니다.(예를 들면 1;2;3) match함수에 대해서는 스터디 정리글에서 자세히 다뤄보도록 하겠습니다!

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

아앗 그리고 저 부분 오타입니닷,,,,RergExp가 아니라 RegExp에요 급해서 디버깅 안하고 내버려서^.^;;;; 사실 틀린 코드여서 안돌아갑니닷....

@GeumZu

GeumZu commented Feb 11, 2025

Copy link
Copy Markdown
Author

수고하셨습니다! 제가 완전 초보라서 질문만 적어두고 가네요..

저도 완전 초보2입니닷,,,,

Comment thread src/App.js Outdated
const customDelimeterMatch = input.match(/^\/\/(.)\n(.*)/);

if (customDelimeterMatch) {
delimiter = new RergExp(customDelimeterMatch[1]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

커스텀 구분자가 있으면 기본 구분자는 작동하지 않는 방식인 거 같네요
만약 둘 다 사용하고 싶으면 delimiter의 []안에 customDelimeterMatch를 넣으면 될 것 같네요!

Comment thread src/App.js
});

return numbers.reduce((sum, num) => sum + num, 0);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

map을 사용해서 배열을 순회하여 Number를 적용하셨네요
저는 reduce과정에서 Number를 적용하여 배열 순회를 덜하도록 코드를 작성했어요
const sum = inputArr.reduce((acc, cur) => {
const num = Number(cur);
(...)
}, 0);

이렇게 하면 시간복잡도 측면에서 조금 더 효율적이라고 하더라구요
근데 물론 큰 차이는 없는거 같긴 해요..ㅎㅎ

Comment thread src/App.js
if (!input) return 0;

let delimiter = /[,:]/;
const customDelimeterMatch = input.match(/^\/\/(.)\n(.*)/);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

26행에서 (/^//(.)\n(.*)/)이 무슨 뜻인지 알 수 있을까요?
코드를 직접 돌려봤는데 실행이 잘 안 되는 거 같아서
이 부분이 무슨 뜻인지 알고 싶네요!

Comment thread src/App.js
const app = new App();
app.play();

export default App;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

index없이 하나의 파일로 합치셨네요!
코드길이가 길지 않아서 이런 구조도 괜찮은 거 같습니다

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants