I want to arrange a datamap with a internal structure like (dm:‘string’,number)
And the only way I came up with is the (for:) loop way like below
(set:$sample to (dm:
'a',1,
'b',5,
'c',2
))
(set:$newsample to (dm:))
(set:$finalsample to (dm:))
(for: each _i,...(datanames:$sample) )[
(set:$newsample to it + (dm:$sample's (_i),_i))
]
(set:$arrange to(sorted:...(datanames:$newsample)))
(for:each _i,...$arrange)[
(set:$finalsample to it +(dm: $newsample's (_i),_i))
]
(print:$bb)
basically I revert the structure of (dm:‘string’,number) to (dm: number,‘string’)
and use the (sorted:) marco to sort the (datanames:) of new datamap, and then revert it back
But I kind thinks it might not a little slower, So is ther a better way to do the trick?
just like the (sorted) marco to arrays
Thanks!
(set:$sample to (dm:
'a',2,
'b',5,
'c',2
))
I just realize it wont work because if the structure is (dm: number,‘string’) like above,
then if it has a repeat number 2, then the data value would override the previous one
NOW I don’t know how to do compeletely