Sorting the array of string based on the custom order

I have the array of strings that I want to sort in a custom order
My array looks like this

[“E”, “D”, “CC”, “C”, “B”, “BB”, “BBB”, “A”, “AA”]

My expected result should look like this
[“AA”, “A”, “BBB”, “BB”, “B”, “CC”, “C”, “D”, “E”]

I tried to sort using the default sort() function but it didn’t give me expected results. So please give your suggestions