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

Cannot specify ascending or descending order #1

Open
sheedo opened this issue Jul 10, 2020 · 5 comments
Open

Cannot specify ascending or descending order #1

sheedo opened this issue Jul 10, 2020 · 5 comments

Comments

@sheedo
Copy link

sheedo commented Jul 10, 2020

I am trying to specify the order in which the map should be sorted, but by default it is sorted in descending order.

@sheedo
Copy link
Author

sheedo commented Jul 10, 2020

In case someone else stumbles across this issue, you can use this approach:

map= Map.fromEntries( map.entries.toList() ..sort( (e1, e2) => e2.key.compareTo(e1.key), ), );

If you want to change between ascending or descending, just swap the parameters used in the comparison, so change this:

e2.key.compareTo(e1.key), to e1.key.compareTo(e2.key),

@yenyichau
Copy link

In case someone else stumbles across this issue, you can use this approach:

map= Map.fromEntries( map.entries.toList() ..sort( (e1, e2) => e2.key.compareTo(e1.key), ), );

If you want to change between ascending or descending, just swap the parameters used in the comparison, so change this:

e2.key.compareTo(e1.key), to e1.key.compareTo(e2.key),

Thanks !

@ameeruljunaidi
Copy link

In case someone else stumbles across this issue, you can use this approach:

map= Map.fromEntries( map.entries.toList() ..sort( (e1, e2) => e2.key.compareTo(e1.key), ), );

If you want to change between ascending or descending, just swap the parameters used in the comparison, so change this:

e2.key.compareTo(e1.key), to e1.key.compareTo(e2.key),

Thank you!

@waqadArshad
Copy link

Thanks, bud! I appreciate the help.

@waqadArshad
Copy link

Thanks, bud! I appreciate the help.

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

4 participants