Skip to content

Conversation

@ssi02014
Copy link
Contributor

@ssi02014 ssi02014 commented Oct 29, 2025

Overview

as-is

Number.isNaN(num) || num <= 0 || num > 30 || !Number.isInteger(num) || !Number.isFinite(num)

기존 as-is 로직은 다음과 같은 과정으로 진행합니다.

1. num이 NaN인지 체크
2. NaN이 아니라면 num이 0 이하 또는 30 초과인지 체크
3. 0 이하 또는 30 초과라면 정수인지 체크
4. 정수가 아니라면(실수라면) num이 유한수(+Infinity, -Infinity, NaN이 아님)인지 체크

하지만 Number.isInteger가 앞쪽에 위치한다면 불 필요한 검증을 줄여 코드를 개선 할 수 있습니다.

to-be

!Number.isInteger(num) || num <= 0 || num > 30

Number.isInterger를 통해 Infinity, -Infinity, NaN, 실수 체크를 한번에 처리할 수 있습니다.

Number.isInteger(NaN); // false
Number.isInteger(Infinity); // false
Number.isInteger(-Infinity); // false
Number.isInteger(0.1); // false

Number.isInteger("10"); // false
Number.isInteger(true); // false
Number.isInteger(false); // false
Number.isInteger([1]); // false

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger#using_isinteger

검증 로직의 !Number.isInteger(num) 이후 순서부터는 num은 정수임을 보장하기 때문에 이제 범위 체크만을 진행 함으로써 검증 로직을 개선해볼 수 있습니다.

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.

@changeset-bot
Copy link

changeset-bot bot commented Oct 29, 2025

⚠️ No Changeset found

Latest commit: d66d5fe

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

@vercel
Copy link

vercel bot commented Oct 29, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
es-hangul Ready Ready Preview Comment Oct 29, 2025 9:32am

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.

1 participant