Skip to content

Instantly share code, notes, and snippets.

@usametov
Created March 27, 2018 01:56
Show Gist options
  • Save usametov/0affb56341e5728b8a617de7df7bcdf5 to your computer and use it in GitHub Desktop.
Save usametov/0affb56341e5728b8a617de7df7bcdf5 to your computer and use it in GitHub Desktop.
const features = [{
'name': 'feature1',
'tags': [{
'weight': 10,
'tagName': 't1'
}, {
'weight': 20,
'tagName': 't2'
}, {
'weight': 30,
'tagName': 't3'
}]
},
{
'name': 'feature2',
'tags': [{
'weight': 40,
'tagName': 't1'
}, {
'weight': 5,
'tagName': 't2'
}, {
'weight': 70,
'tagName': 't3'
}]
},
{
'name': 'feature3',
'tags': [{
'weight': 50,
'tagName': 't1'
}, {
'weight': 2,
'tagName': 't2'
}, {
'weight': 80,
'tagName': 't3'
}]
}
];
const result = _.flatMap(features, item =>
_.map(item.tags, tag => _.defaults({ name: item.name }, tag))
);
console.log(result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment