I have a map that looks like this:
user> (frequencies "aaabccddddee")
{\a 3, \b 1, \c 2, \d 4, \e 2}
And I would like to have a function that sorted key / value pairs according to the order that each character appears in the string that I would pass as an argument.
Something like that:
user> (somesort "defgcab" (frequencies "aaabccddddee"))
[[\d 4] [\e 2] [\c 2] [\a 3] [\b 1]]
(in the above example, "f" and "g" are not displayed on the map, and therefore are ignored. It is guaranteed that the string - "defgcab" in this example - must contain each character / key on the map)
The resulting collection does not matter much while it is sorted.
I have tried several things but cannot find a way to make this work.
source
share