Skip to content

feat(orderBy, sortBy): improve orderBy, sortBy#1552

Open
jidohyun wants to merge 4 commits intotoss:mainfrom
jidohyun:feat/sortby-string-array
Open

feat(orderBy, sortBy): improve orderBy, sortBy#1552
jidohyun wants to merge 4 commits intotoss:mainfrom
jidohyun:feat/sortby-string-array

Conversation

@jidohyun
Copy link

@jidohyun jidohyun commented Dec 9, 2025

This PR improve the orderBy, sortBy function, as requested in the issue(#869)

Added:

  • sortBy and orderBy string array support: Enhanced both functions to work with primitive arrays (strings, numbers, etc.) by removing T extends object constraint
  • Optional criteria parameters: Made criteria parameter optional with default empty array, enabling direct primitive sorting without explicit functions
  • Optional orders parameter: Added default ascending order to orderBy for simplified usage
  • Comprehensive test cases: Added tests for string arrays, number arrays, empty criteria, and mixed sorting scenarios using consistent ['apple', 'banana', 'cherry'] pattern
  • Enhanced documentation: Updated JSDoc with primitive array examples and usage patterns for both Korean and English docs
  • Type safety improvements: Maintained full type inference while supporting broader input types
  • Backward compatibility: Preserved all existing object sorting functionality without breaking changes

Here is the screenshot of the performance benchmark results:
Screenshot 2025-12-09 at 12 20 33 PM
Screenshot 2025-12-09 at 12 21 03 PM

- Remove T extends object constraint to support all types including primitives
- Add optional criteria parameter with default empty array for primitive sorting
- Add optional orders parameter with default ascending order in orderBy
- Update JSDoc to document primitive array support with examples
- Add comprehensive test cases for string and number arrays
- Support both explicit criteria (functions) and automatic primitive sorting
- Maintain backward compatibility with existing object sorting functionality
@vercel
Copy link

vercel bot commented Dec 9, 2025

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

Project Deployment Preview Comments Updated (UTC)
es-toolkit Ready Ready Preview Comment Dec 9, 2025 5:16am

@jidohyun jidohyun closed this Dec 9, 2025
@jidohyun jidohyun reopened this Dec 9, 2025
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