Skip to content

Instantly share code, notes, and snippets.

@TehShrike
Last active February 24, 2017 20:38
Show Gist options
  • Save TehShrike/156238dc513a8a4f21fe9b996b4f842d to your computer and use it in GitHub Desktop.
Save TehShrike/156238dc513a8a4f21fe9b996b4f842d to your computer and use it in GitHub Desktop.
One-to-many zip
const parent = [
{ name: 'cool dad', coolness: 3 },
{ name: 'cool cat', coolness: 7 }
]
const children = [
{ name: 'bobby', coolness: 1 },
{ name: 'billy', coolness: 3 },
{ name: 'bubba', coolness: 5 },
{ name: 'benji', coolness: 6 }
]
const output = oneToManyZip({ parent, children }, function childMatchesParent({ parent, children }) {
if (parent.coolness >= children.coolness) {
return true
}
})
const expectedOutput = [
{
parent: { name: 'cool dad', coolness: 3 },
children: [
{ name: 'bobby', coolness: 1 },
{ name: 'billy', coolness: 3 }
]
}, {
parent: { name: 'cool cat', coolness: 7 },
children: [
{ name: 'bubba', coolness: 5 },
{ name: 'benji', coolness: 6 }
]
}
]
t.deepEqual(output, expectedOutput)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment