-
Notifications
You must be signed in to change notification settings - Fork 13
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
feat(utils): countOccurrencesInArray 유틸 함수 추가 #159
Conversation
🦋 Changeset detectedLatest commit: 86bd10c The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
export const isArray = <T extends readonly any[]>( | ||
value: unknown | ||
): value is T => { |
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.
일반적인 배열 뿐만아니라 readonly 배열
까지 타입 추론을 원활하게 하기 위해 <T extends readonly any[]>
로 변경하였습니다. 이를 통해 더욱 유연한 타입 지정을 할 수 있습니다! 🙏
const readonlyTestArray = ['foo'] as const; | ||
|
||
if (isArray(readonlyTestArray)) { | ||
expectTypeOf(readonlyTestArray).toEqualTypeOf<readonly ['foo']>(); |
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.
기존대로라면 readonlyTestArray는 readonly ['foo'] & any[]
로 타입이 잡혀 타입 에러가 발생합니다.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #159 +/- ##
==========================================
+ Coverage 94.53% 94.59% +0.06%
==========================================
Files 74 75 +1
Lines 677 685 +8
Branches 155 157 +2
==========================================
+ Hits 640 648 +8
Misses 31 31
Partials 6 6
|
@Sangminnn 간단한 유틸 함수들은 리뷰어만 추가하고 머지하도록 하겠습니다! |
Overview
issue: #157
입력한 배열에서 배열의 각 요소들이 등장한 횟수를 카운팅 해주는
countOccurrencesInArray
입니다.단,
Object
,Array
,Set
,Map
과 같은 객체 타입은 카운팅에서 제외되며,null
,NaN
,undefined
는 카운팅에 포함됩니다.PR Checklist
Contributing Guide