16/03/28 13:51:42.42 ObwLfSdF.net
>>342 Squeak/Pharo Smalltalk
| fn |
fn := [:seq |
| rule |
rule := [:a :b |
a key > b key or: [
a key = b key and: [(seq indexOf: a value) < (seq indexOf: b value)]]].
seq class streamContents: [:ss |
(seq asBag sortedCounts sort: rule) do: [:kv |
kv key timesRepeat: [ss nextPut: kv value]]]
].
fn value: 'Hello world'.
"=> 'lllooHe wrd' "
fn value: #(3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6).
"=> #(3 3 3 3 5 5 5 9 9 9 1 1 4 4 2 2 6 6 8 8 7) "