I'm using the following code (courtesy of [JQuery Javascript Sort Array by Highest Count](https://stackoverflow.com/questions/19464440/jquery-javascript-sort-array-by-highest-count?noredirect=1&lq=1)) to sort a list of strings from highest to lowest count:

```
var items = {}, sortableItems = [], i, len, element, listOfStrings; 

    listOfStrings = JSON.parse(the_chems);

for (i = 0, len = listOfStrings.length; i < len; i += 1) 
    {
        if (items.hasOwnProperty(listOfStrings[i])) {
            items[listOfStrings[i]] += 1;
        } else {
            items[listOfStrings[i]] = 1;
        }
    }

for (element in items) 
    {
        if (items.hasOwnProperty(element)) {
            sortableItems.push([element, items[element]]);
        }
    }

sortableItems.sort(function (first, second) 
    {
        return second[1] - first[1];
    });

```

Instead of this type of array input 

```
["red", "red", "red", "blue", "blue"]

```

Which returns 

```
[ [ "red", 3 ], [ "blue", 2 ] ]

```

I would like to use an array like 

```
[["red","apple"], ["red","chilli"], ["red","melon"], ["blue","ocean"], ["blue","eyes"]]

```

And return

```
[["red", 3, ["apple","chilli","melon"]], ["blue", 2, ["blue","ocean"]]

```