Skip to content

sortBy with string[] #869

Closed
Closed

Description

@gurgeous

Thanks for creating es-toolkit, we are migrating today and love it. Really appreciate all your hard work!

It would be nice if sortBy/orderBy supported an array of strings. This is pretty common IMO and worked with lodash. Ordering by lower case, or by string length, or some kind of category lookup, or natural sort, or first word in a sentence, etc. Thanks again!

Activity

  1. raon0211 commented on Dec 7, 2024

    @raon0211
    Collaborator

    Hello :) Let us look into this.

  2. gurgeous commented on Dec 7, 2024

    @gurgeous
    Author

    Great, let me know if I can help! I think compat/sortBy handles it appropriately

  3. raon0211 commented on Jul 5, 2026

    @raon0211
    Collaborator

    Thank you for the suggestion, and I'm glad to hear that you're enjoying es-toolkit!

    After some consideration, though, I believe that for arrays of strings, using the native sort directly is much more natural and better ergonomics:

    arr.sort((x, y) => x.localeCompare(y));
    
    // By lower case
    arr.sort((x, y) => x.toLowerCase().localeCompare(y.toLowerCase()));
    
    // By string length
    arr.sort((x, y) => x.length - y.length);

    sortBy and orderBy are designed for sorting arrays of objects by their properties, and extending them to primitives would add complexity to the API without a clear benefit over what modern JavaScript already provides.

    So I'll close this issue. Thanks again for your interest in es-toolkit!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions