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): flatten 신규 유틸 함수 추가 #303

Merged
merged 3 commits into from
Jul 4, 2024
Merged

Conversation

ssi02014
Copy link
Contributor

@ssi02014 ssi02014 commented Jul 4, 2024

Overview

Issue: #302

중첩 배열을 평탄화해주는 함수입니다. depth 옵션으로 평탄화 깊이를 직접 지정 할 수 있습니다.

JS에서 기본적으로 제공하는 Array.prototype.flat은 성능이 좋지 않습니다.

제공하는 flatten 함수는 JS의 flatlodash의 flattenDepth보다 성능적으로 우수합니다.

스크린샷 2024-07-05 오전 12 52 52

Example

해당 함수는 기존 Array.prototype.flat와 동일하게 depth 값에 따른 타입 추론을 원활하게 해줍니다

const arr = [1, [2, [3, [4, [5]]]]];

flatten(arr, 1); 
// value: [1, 2, [3, [4, [5]]]]
// type: (number | (number | (number | number[])[])[])[]

flatten(arr, 2); 
// value: [1, 2, 3, [4, [5]]]
// type: (number | (number | number[])[])[]

flatten(arr, 3); 
// value: [1, 2, 3, 4, [5]]
// type: (number | number[])[]

flatten(arr, 4); 
// value: [1, 2, 3, 4, 5]
// type: number[]

PR Checklist

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

@ssi02014 ssi02014 added feature 새로운 기능 추가 @modern-kit/utils @modern-kit/utils labels Jul 4, 2024
@ssi02014 ssi02014 requested a review from Sangminnn July 4, 2024 15:55
@ssi02014 ssi02014 self-assigned this Jul 4, 2024
Copy link

changeset-bot bot commented Jul 4, 2024

🦋 Changeset detected

Latest commit: c879138

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

@ssi02014
Copy link
Contributor Author

ssi02014 commented Jul 4, 2024

@Sangminnn 성능적으로 우수한 flatten 함수를 추가하고, 이를 기반으로 deepFlatThenMap과 더불어 flatMapDeep 을 개선하고자 합니다 🤗

Copy link

codecov bot commented Jul 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.91%. Comparing base (c85b3f4) to head (cf09195).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #303      +/-   ##
==========================================
+ Coverage   96.88%   96.91%   +0.02%     
==========================================
  Files         123      124       +1     
  Lines        1284     1296      +12     
  Branches      312      315       +3     
==========================================
+ Hits         1244     1256      +12     
  Misses         34       34              
  Partials        6        6              
Components Coverage Δ
@modern-kit/react 94.55% <ø> (ø)
@modern-kit/utils 100.00% <100.00%> (ø)

@ssi02014 ssi02014 merged commit cf117da into main Jul 4, 2024
2 checks passed
@ssi02014 ssi02014 deleted the feat/flatten branch July 4, 2024 16:12
@ssi02014
Copy link
Contributor Author

toss/es-toolkit#147
es-toolkit에 추가됐습니다 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature 새로운 기능 추가 @modern-kit/utils @modern-kit/utils
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant