Last active
February 24, 2017 20:38
-
-
Save TehShrike/156238dc513a8a4f21fe9b996b4f842d to your computer and use it in GitHub Desktop.
One-to-many zip
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 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