I'm facing a challenge where I need to restructure an array, but I'm not sure where to begin.
Here is the original array:
var products =
[
"rose-S",
"rose-M",
"rose-L",
"rose-XL",
"rose-XL",
"blue-XS",
"blue-L",
"green-M"
]
The desired structure should be:
{
"rose": {
"S": 1,
"M": 1,
"L": 1,
"XL": 2
},
"blue": {
"XS": 1,
"L": 1
},
"green": {
"M": 1
},
}
What are some steps I could take to achieve this restructuring?