I have an array with playing cards. I would like to sort these on value, color and playability.
- I have 4 colors; 1, 2, 3, 4.
- I have 3 playability options; 1, 2, 3.
- I have 5 values; 1, 2, 3, 4, 5.
I am able to sort the array on color and value. So if the color is the same, the array is sorted on value.
example color-value pairs:
1-2, 1-4, 1-5, 2-2, 3-1, 3-2, 3-5
Code is,
playerCards.sort {
if $0.colorSorter == $1.colorSorter {
return $0.value < $1.value
}
return $0.colorSorter < $1.colorSorter
}
How do I add the third paramater to sort on playability additionally?
What I would like to see (playability-color-value triplets):
1-1-2, 1-1-4, 1-2-2, 1-3-1, 2-1-5, 2-3-1, 2-3-2, 3-3-5
1: sort on playability 2: sort on color 3: sort on value.
Thanks!