Sorting things other than a simple list

Post your questions and help other users.

Moderator: Martin

Post Reply
dah
Posts: 20
Joined: 25 Feb 2014 17:15

Sorting things other than a simple list

Post by dah » 05 Sep 2014 20:56

Hi,

I have a map where the values are counts. I'd like to get a list of the keys which is sorted by these counts.

Is there a way to do this? It seems the 'sort' function isn't usefull here, am I right?

Best regards,
Daniel

User avatar
kintrupf
Posts: 257
Joined: 10 Sep 2013 08:59

Re: Sorting things other than a simple list

Post by kintrupf » 05 Sep 2014 21:17

dah wrote:Hi,

I have a map where the values are counts. I'd like to get a list of the keys which is sorted by these counts.

Is there a way to do this? It seems the 'sort' function isn't usefull here, am I right?
Oh, you'll need the sort function ;)
Use it in combination with the getMapKeys function. This will result in a sorted list of all keys of the map.
Somthing like this in a script action or an expression condition:

Code: Select all

sortedList = sort(getMapKeys(yourMap));

dah
Posts: 20
Joined: 25 Feb 2014 17:15

Re: Sorting things other than a simple list

Post by dah » 06 Sep 2014 20:48

Thanks, but I need a list of the keys that is sorted by the values of the map (the counts).

For example:

map = {
foo: 3,
bar: 1,
baz: 10
}

would result in the list:

- bar
- foo
- baz

Post Reply