Array not working as intended?

Instead of spending hours trying to fix this, I've opted to just give each colour and group a number, i.e val == '1' is redGroup[0] and val=='2' is redGroup[1] etc.

It isn't the most elegant solution, but it does make it work