How to ‘melt’ a wide table/array in google app script?

I have an array/table in Google Sheets with data in the following format:

Catergory1 A A A A A B B B B B C C C C C
Catergory2 Q1 Q2 Q3 Q4 Q5 Q1 Q2 Q3 Q4 Q5 Q1 Q2 Q3 Q4 Q5
Propotions 34% 66% 9% 49% 31% 36% 69% 1% 10% 20% 98% 38% 21% 57% 76%

I want to use Google App Script to convert this array into the following format:

Catergory1 Q1 Q2 Q3 Q4 Q5
A 34% 66% 9% 49% 31%
B 36% 69% 1% 10% 20%
C 98% 38% 21% 57% 76%

Thanks in advance.