If it were me, I probably would store each card as a string in that case — "7H" for 7 of hearts, etc. Then you could sort them easily.
However, there is another sorting feature you may not know about, which is more intended for cases like this. list.sort
takes an optional byKey
parameter, which is a key to look up in each element, to sort by that. Example:
dogs = []
dogs.push {"name":"poodle", "size":2}
dogs.push {"name":"dachshund", "size":1}
dogs.push {"name":"collie", "size":3}
dogs.push {"name":"wolfhound", "size":4}
dogs.sort "name"
print "By name:" + dogs
dogs.sort "size"
print "By size:" + dogs
(Try it here.)