I have an array containing several dictionaries. How can I sorted them using a key that each dictionary have like age?
an Array((a Dictionary('age'->'20' 'ID'->1254))(a Dictionary('age'->'35' 'ID'->1350))(a Dictionary('age'->'42' 'ID'->1425)))
I have an array containing several dictionaries. How can I sorted them using a key that each dictionary have like age?
an Array((a Dictionary('age'->'20' 'ID'->1254))(a Dictionary('age'->'35' 'ID'->1350))(a Dictionary('age'->'42' 'ID'->1425)))
Copyright © 2021 Jogjafile Inc.
You can sort by providing a comparator block; the block takes two arguments (two elements from the array) and is expected to return boolean.
sorted:
will return a sorted collection without changing the receiversort:
will perform the sorting in-place and return itselfYou can also use
asSortedCollection:
which will create a new collection that always upholds the sorting invariant.