Skip to content

feat(unzipWith): Implement compat/unzipWith #1118

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

Merged
merged 11 commits into from
Apr 30, 2025
Merged

Conversation

L2HYUNN
Copy link
Contributor

@L2HYUNN L2HYUNN commented Apr 5, 2025

close: #994

Implement

I’m considering two different ways to implement the unzipWith function, and I’m debating whether to use a for loop or the map method.

Would love to hear thoughts on which approach is more suitable here.

for-loop

export function unzipWith<T>(
  array: T[][] | ArrayLike<ArrayLike<T>> | null | undefined,
  iteratee?: ((...args: any[]) => unknown) | null
): any[] {
  if (!isArrayLikeObject(array) || !array.length) {
    return [];
  }

  const unziped = isArray(array) ? unzipToolkit(array) : unzipToolkit(Array.from(array, value => Array.from(value)));

  if (!iteratee) {
    return unziped;
  }

  const result: any[] = new Array(unziped.length);

  for (let i = 0; i < unziped.length; i++) {
    const value = unziped[i];

    result[i] = iteratee(...value);
  }

  return result;
}

map

export function unzipWith<T>(
  array: T[][] | ArrayLike<ArrayLike<T>> | null | undefined,
  iteratee?: ((...args: any[]) => unknown) | null
): any[] {
  if (!isArrayLikeObject(array) || !array.length) {
    return [];
  }

  const unziped = isArray(array) ? unzipToolkit(array) : unzipToolkit(Array.from(array, value => Array.from(value)));

  if (!iteratee) {
    return unziped;
  }

  return unziped.map(item => iteratee(...item));
}

Test

image

Bench

스크린샷 2025-04-05 오후 12 35 05

Copy link

vercel bot commented Apr 5, 2025

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

Name Status Preview Comments Updated (UTC)
es-toolkit ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 30, 2025 11:15am

@codecov-commenter
Copy link

codecov-commenter commented Apr 5, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.23%. Comparing base (aa5ab9e) to head (aa52449).
Report is 2 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1118   +/-   ##
=======================================
  Coverage   99.23%   99.23%           
=======================================
  Files         437      438    +1     
  Lines        3906     3917   +11     
  Branches     1153     1156    +3     
=======================================
+ Hits         3876     3887   +11     
  Misses         30       30           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

raon0211
raon0211 previously approved these changes Apr 30, 2025
Copy link
Collaborator

@raon0211 raon0211 left a comment

Choose a reason for hiding this comment

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

Perfect work!

@raon0211 raon0211 merged commit f149e1f into toss:main Apr 30, 2025
3 of 9 checks passed
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.

Add unzipWith to compat package
3 participants