Skip to content

Instantly share code, notes, and snippets.

@jackdh
Last active October 8, 2018 07:27
Show Gist options
  • Save jackdh/b78145fce2ce2f3231a88ca409641161 to your computer and use it in GitHub Desktop.
Save jackdh/b78145fce2ce2f3231a88ca409641161 to your computer and use it in GitHub Desktop.
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-js -->
const one = [
{
name: 'CRISPS', items: [{ name: 'salty crisps',items: [] }]
},
{
name: 'CHOCOLATE', items: [{ name: 'full sized bars', items: [] }]
}
]
const two = [
{
name: 'CRISPS', items: [{ name: 'salty crisps',items: [] }]
},
{
name: 'DRINKS', items: [{ name: 'fizzy drinks',items: [] }]
},
{
name: 'CHOCOLATE', items: [{ name: 'small sized bars', items: [] }]
}
]
const merge = (p, ...arrs) => [...new Set([].concat(...arrs).map(a => JSON.stringify(a)))].map(a => JSON.parse(a));
const three = merge('name', one, two);
console.log(three);
<!-- end snippet -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment