How are map cards sorted by color?

For example

After the grid method of cleanup is executed, the same colors are grouped together for sorting, such as

How to do it?

I’ve already answered in your other thread, see there.

The same processes apply in each case, so this is a duplicate although I quite understand you weren’t to know that when asking. I’ll lock this thread and take any follow up questions on the sort by prototype thread as the only difference is the thing (attribute) being sorted upon.