Skip to content

Syntax suggestion #12

@mesqueeb

Description

@mesqueeb

I thought of a super clean syntax for your great NPM library @jonschlinkert .

Usage

  • In case of single attribute sort: sort asc with string and desc with -+string
  • In case of multiple attribute sort: add the attributes in an array with the same asc/desc functionality as above

Examples

Single attribute reverse (desc) sort:

let arr = [{foo: 'y'}, {foo: 'z'}, {foo: 'x'}]

arraySort(arr, '-foo')
// Will sort on attribute `foo` as `desc`

Multiple attribute asc & desc sort:

let arr = [{foo: 'y', bar: 'a'}, {foo: 'z', bar: 'b'}, {foo: 'x', bar: 'c'}, {foo: 'x', bar: 'a'}]

arraySort(arr, ['foo', '-bar'])
// Will sort on attribute `foo` as `asc`
//      will sort next on `bar` as `desc`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions