Hello guys I'm trying to parse an array of strings into a custom structure:

```
var str = [
"country.UK.level.1",
"country.UK.level.2",
"country.US.level.1",
"country.UK.level.3"
];

```

Into something like:

```
var ordered = {
   "country": [
      {"UK" : {"level" : ["1", "2", "3"]}},
      {"US" : {"level" : ["1","2"]}}
   ]
}

```

Notes:

* Strings stored in the `str` array will not be sorted and the code should be robust against that.
* Strings will follow the `x.y.x.y...` pattern, where `x` will be unique for that array and `y` can change. In my example `country` and `level` will always be the same as they represent the `x` pos.
* This requires recursive approach as the strings stored in the `str` array, can be of any length. The longer the string the deeper nesting.