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

feat(utils): countOccurrencesInArray 유틸 함수 추가 #159

Merged
merged 2 commits into from
May 23, 2024
Merged

Conversation

ssi02014
Copy link
Contributor

@ssi02014 ssi02014 commented May 23, 2024

Overview

issue: #157
입력한 배열에서 배열의 각 요소들이 등장한 횟수를 카운팅 해주는 countOccurrencesInArray입니다.
단, Object, Array, Set, Map과 같은 객체 타입은 카운팅에서 제외되며, null, NaN, undefined는 카운팅에 포함됩니다.

PR Checklist

  • All tests pass.
  • All type checks pass.
  • I have read the Contributing Guide document.
    Contributing Guide

@ssi02014 ssi02014 added documentation 문서 추가 및 수정 feature 새로운 기능 추가 @modern-kit/utils @modern-kit/utils fix 버그 수정 및 코드 개선 labels May 23, 2024
@ssi02014 ssi02014 self-assigned this May 23, 2024
Copy link

changeset-bot bot commented May 23, 2024

🦋 Changeset detected

Latest commit: 86bd10c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@modern-kit/utils Minor

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

Comment on lines +1 to +3
export const isArray = <T extends readonly any[]>(
value: unknown
): value is T => {
Copy link
Contributor Author

@ssi02014 ssi02014 May 23, 2024

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[]>로 변경하였습니다. 이를 통해 더욱 유연한 타입 지정을 할 수 있습니다! 🙏

Comment on lines +20 to +23
const readonlyTestArray = ['foo'] as const;

if (isArray(readonlyTestArray)) {
expectTypeOf(readonlyTestArray).toEqualTypeOf<readonly ['foo']>();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

기존대로라면 readonlyTestArray는 readonly ['foo'] & any[] 로 타입이 잡혀 타입 에러가 발생합니다.

Copy link

codecov bot commented May 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.59%. Comparing base (589dd5b) to head (86bd10c).

Additional details and impacted files

Impacted file tree graph

@@            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              
Components Coverage Δ
@modern-kit/react 90.28% <ø> (ø)
@modern-kit/utils 100.00% <100.00%> (ø)

@ssi02014 ssi02014 requested a review from Sangminnn May 23, 2024 07:40
@ssi02014
Copy link
Contributor Author

ssi02014 commented May 23, 2024

@Sangminnn 간단한 유틸 함수들은 리뷰어만 추가하고 머지하도록 하겠습니다!
나중에 여유로울 때 한번 확인해주시고, 추가 의견있으시면 주시면 감사드립니다! 🤗🙏

@ssi02014 ssi02014 merged commit 7842e3e into main May 23, 2024
3 checks passed
@ssi02014 ssi02014 deleted the feat/array branch May 23, 2024 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation 문서 추가 및 수정 feature 새로운 기능 추가 fix 버그 수정 및 코드 개선 @modern-kit/utils @modern-kit/utils
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant