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

fix: numberToHangulMixed 및 numberToHangul에 모든 number 처리 #323

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

gs18004
Copy link

@gs18004 gs18004 commented Jan 26, 2025

Overview

numberToHangulMixednumberToHangul가 양의 정수 뿐만 아니라 소수, 음수, 무한대 또한 처리할 수 있게 수정하였습니다.

PR Checklist

  • I read and included theses actions below
  1. I have read the Contributing Guide
  2. I have written documents and tests, if needed.

Copy link

vercel bot commented Jan 26, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
es-hangul ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 10, 2025 3:30am

@po4tion
Copy link
Collaborator

po4tion commented Feb 1, 2025

@gs18004 님 안녕하세요! 먼저 예외 처리를 추가해주셔서 정말 감사드립니다.

현재 작업이 매우 훌륭해 보이는데요, 혹시 괜찮으시다면 numberToHangulMixed 문서에도 조금 더 자세한 설명을 덧붙여주실 수 있을까요? 그러면 처음 사용하시는 분들도 테스트 코드를 보지 않고 바로 이해하실 수 있을 것 같아요.

numberToHangulMixed 안내에는 단순히 “한글의 숫자 단위”라고만 되어 있는데, 이 표현이 조금 모호하게 느껴질 수 있을 것 같아요. 해당 문장도 함께 다듬어주시면 정말 감사하겠습니다!

제가 생각해본 예시는 아래와 같습니다. 그대로 사용하셔도 좋고, 자유롭게 변경해주셔도 좋습니다.

정수로 주어진 숫자에 한해 4자리마다 달라지는 한글의 숫자 단위를 자동으로 붙여주며, 다양한 요구 사항에 맞춰 ‘만(萬)’ 단위 기준으로 띄어쓰기도 지원합니다.

마지막으로, 기여해주셔서 다시 한 번 감사드립니다! 궁금하신 점 있으시면 언제든 말씀해 주세요.

@gs18004
Copy link
Author

gs18004 commented Feb 1, 2025

@gs18004 님 안녕하세요! 먼저 예외 처리를 추가해주셔서 정말 감사드립니다.

현재 작업이 매우 훌륭해 보이는데요, 혹시 괜찮으시다면 numberToHangulMixed 문서에도 조금 더 자세한 설명을 덧붙여주실 수 있을까요? 그러면 처음 사용하시는 분들도 테스트 코드를 보지 않고 바로 이해하실 수 있을 것 같아요.

numberToHangulMixed 안내에는 단순히 “한글의 숫자 단위”라고만 되어 있는데, 이 표현이 조금 모호하게 느껴질 수 있을 것 같아요. 해당 문장도 함께 다듬어주시면 정말 감사하겠습니다!

제가 생각해본 예시는 아래와 같습니다. 그대로 사용하셔도 좋고, 자유롭게 변경해주셔도 좋습니다.

정수로 주어진 숫자에 한해 4자리마다 달라지는 한글의 숫자 단위를 자동으로 붙여주며, 다양한 요구 사항에 맞춰 ‘만(萬)’ 단위 기준으로 띄어쓰기도 지원합니다.

마지막으로, 기여해주셔서 다시 한 번 감사드립니다! 궁금하신 점 있으시면 언제든 말씀해 주세요.

감사합니다 동규님! 문서도 수정해서 올려 보겠습니다.

Copy link

changeset-bot bot commented Feb 1, 2025

⚠️ No Changeset found

Latest commit: a031844

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@gs18004 gs18004 changed the title fix: numberToHangulMixed에 예외처리 추가 fix: numberToHangulMixed 및 numberToHangul에 모든 number 처리 Feb 6, 2025
@gs18004
Copy link
Author

gs18004 commented Feb 6, 2025

@okinawaa 말씀하신 부분 반영해놓았습니다. 혹시 더 바꿀 부분이 있을까요?

@okinawaa
Copy link
Member

okinawaa commented Feb 7, 2025

@gs18004 제가 주말까지 리뷰하도록 할게요 너무 감사합니다.

@gs18004
Copy link
Author

gs18004 commented Feb 7, 2025

@gs18004 제가 주말까지 리뷰하도록 할게요 너무 감사합니다.

감사합니다! 좋은 주말 되세요 :)

}

return koreanParts.join('');
return isNegative ? (options?.spacing ? '마이너스 ' + result : '마이너스' + result) : result;
Copy link
Member

Choose a reason for hiding this comment

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

마지막 return 문에서 삼항 연산자가 중첩되어 있어서 가독성이 다소 좋지 않을 수 있을 것 같아요.
중첩된 삼항 연산자는 한눈에 읽기 어려울 수 있기 때문에, 명확한 if 분기로 나누면 더 직관적으로 이해할 수 있을 것 같습니다.

예를 들어, 아래처럼 작성하면 가독성이 좋아질 것 같아요.

if (isNegative) {
  result = options?.spacing ? `마이너스 ${result}` : `마이너스${result}`;
}

return result;

이렇게 하면 조건에 따라 result를 수정하고, 마지막에 return을 단순화할 수 있어서 코드를 읽는 부담이 줄어들 것 같아요! 😊
어떻게 생각하시나요?

Copy link
Author

Choose a reason for hiding this comment

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

좋은 것 같습니다! 아래 말씀주신 내용까지 모두 반영하여 새로 commit했습니다😄

if (input === 0) {
return '영';
}

const isNegative = input < 0;
if (isNegative) {
input = Math.abs(input);
Copy link
Member

Choose a reason for hiding this comment

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

파라미터(input)를 직접 변경하는 방식보다는, 새로운 변수를 만들어 사용하는 것이 더 명확하고 예측 가능한 코드가 될 것 같아요.

파라미터를 변경하면 함수 내부에서 원래 값이 유지되지 않아 코드 흐름을 따라가기 어려울 수 있고, 예기치 않은 부작용이 발생할 가능성이 있습니다.

예를 들어, 아래와 같이 absoluteInput을 사용하면 원본을 유지하면서 가독성을 높일 수 있을 것 같습니다.

const isNegative = input < 0;
const absoluteInput = Math.abs(input);

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