I'm learning lodash functions and I've been trying to find a method to split a data set and group using lodash. Any immediate help would be highly appreciated.
The dataset is as follows
car:brand:ford,
car:brand:audi,
car:brand:volvo,
car:brand:toyota, lexus,
phone:brand:samsung,
phone:brand:apple, iPhone, xr,
phone:brand:huawei,
phone:brand:nokia, lumia,
And the expected out come with split and grouped is as follows
"car:brand": [
"ford",,
"audi",
"volvo",
"toyota, lexus",
],
"phone:brand": [
"samsung",
"apple, iPhone, xr",
"huawei",
"nokia, lumia",
],
So far I've come up with this part, and I'm stuck. I would like to learn how to do it using lodash _.split mainly
let brand = 'dataset'
let arr = _.chain(brand)
.split('car:brand:')
.join(',')
.split('phone:brand:')
.join(',')
.split(',')
.chunk(2)
.value();
console.log(arr);
This is not successful, is there an efficient way to split and group the data set using lodash functions? Any help would be much appreciated.
Console output
(8) [Array(2), Array(2), Array(2), Array(2), Array(2), Array(2), Array(2), Array(2)]
0: (2) ["", "ford"]
1: (2) ["", "audi"]
2: (2) ["", "volvo"]
3: (2) ["", "toyota"]
4: (2) ["lexus", ""]
5: (2) ["samsung", ""]
6: (2) ["apple", " iPhone"]
7: (2) [" xr", ""]
length: 8
When expanded
0: Array(2)
0: ""
1: "ford"
length: 2
[[Prototype]]: Array(0)