Last active
October 8, 2018 07:27
-
-
Save jackdh/b78145fce2ce2f3231a88ca409641161 to your computer and use it in GitHub Desktop.
This file contains 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
<!-- 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