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

Sort issue #552

Closed
PxyUp opened this issue Feb 8, 2024 · 3 comments
Closed

Sort issue #552

PxyUp opened this issue Feb 8, 2024 · 3 comments

Comments

@PxyUp
Copy link
Contributor

PxyUp commented Feb 8, 2024

Hello @antonmedv !

First of all thanks for this one of the best tool which i know!

Here my problem(i am not sure is it problem or suggestion).

I trying sort array here https://expr-lang.org/playground:

sort(Posts) // or sort(Posts, 'desc')

From my point of view like user i am expect results should array with same order/reverse order here the error (as i understand no way to do that right now):

cannot deref <invalid reflect.Value> (3:1)
 | sort(Posts)
 | ^

My suggestion is: create new function which will be do that: sortByIndex(array, order = 'asc|desc') or create reverse. I am prefer for reverse(but may be need support string as well)

Examples:

sortByIndex([3,2,1)) == [3,2,1]
sortByIndex([3,2,1), 'desc') == [1,2,3]
reverse([3,2,1]) == [1,2,3]
reverse(reverse([3,2,1])) == [3,2,1]

I can create pull request with this function

@antonmedv
Copy link
Member

Yes, sort() is just for array on numbers, and sortBy() is for array structs/maps.

sortBy(Posts, 'Title') | map(.ID)

And sure, lets add reverse().

@PxyUp
Copy link
Contributor Author

PxyUp commented Feb 8, 2024

Adding MR: #553

@antonmedv
Copy link
Member

Added #558

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

No branches or pull requests

2 participants