With a list/array of colors in hexadecimal format like this:
[ "#fff000", "#238923", "#aaaaa0", "#ff2300", "#2ff014", "#010203" ]
The idea is to order/organize it so that the red ones are first, the green ones second, and the blue ones last. But that is not enough because there are tones and tones of colors, the idea would be that they were organized in a "chromatic" way:
- Bluish reds (red is the main color, then blue)
- Reds (red is the main color, blue and green have the same value)
- Greenish reds (red is the main color, then green)
- reddish greens
- Green
- teal greens
- greenish blues
- blues
- reddish blues
As you can see, it would be like a "color circle" where the ends meet: I put blue before green for red, and green before red for blue. So for example: #331122 (bluish red) would come before #330000 (red-red) which would come before #331100 (greenish red). The sort scheme would be something like this:
R G B
-------- -------- --------
RB RR RG GR GG GB BG BB BR
So the above list would look like this:
[ "#ff2300", "#fff000", "#aaaaa0", "#2ff014", "#238923", "#010203" ]
I can't use an existing sort method in the programming language because it's not really a normal sort and it's not going to go alphabetically. That is why the values for the three colors must be taken into account independently. He would have to do something of his own.
So I'm looking for an answer that:
- Propose a theoretical solution for a large number of colors.
- Also work with a limited number of colors (25-50 which could be used to sort a paginated table).
- Be efficient (algorithmic order) - should you consider hashing/buckets?