Created
March 27, 2018 01:56
-
-
Save usametov/0affb56341e5728b8a617de7df7bcdf5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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