-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Open
Description
Unlike pullAll
and pullAllBy
, pullAllWith
appears to match every item in array
with every item in values
until one of them returns true
. This means it does not abide by the same logical contract as the other two functions.
This leads to pullAllWith
removing all items from arrays
if the comparator uses !==
:
Example
Code
const nixEm = [{ name: 'moe' }, { name: 'curly' }]
const keepEm = [{ name: 'manny' }, { name: 'shemp' }]
{
const stooges = ['manny', 'moe', 'curly', 'shemp']
_.pullAll(
stooges,
nixEm.map(n => n.name)
)
console.log(`pullAllResults: ${JSON.stringify(stooges)}`)
}
{
const stooges = [{ name: 'manny' }, { name: 'moe' }, { name: 'curly' }, { name: 'shemp' }]
_.pullAllBy(stooges, nixEm, 'name')
console.log(`pullAllByResults: ${JSON.stringify(stooges)}`)
}
{
const stooges = [{ name: 'manny' }, { name: 'moe' }, { name: 'curly' }, { name: 'shemp' }]
_.pullAllWith(stooges, keepEm, (a, b) => {
const match = a.name !== b.name
console.log(`${a.name} !== ${b.name} = ${match ? 'pull' : 'keep'}`)
return match
})
console.log(`pullAllWithResults: ${JSON.stringify(stooges)}`)
}
Output
'pullAllResults: ["manny","shemp"]'
'pullAllByResults: [{"name":"manny"},{"name":"shemp"}]'
"manny !== manny = keep"
"moe !== manny = pull"
"curly !== manny = pull"
"shemp !== manny = pull"
"manny !== shemp = pull"
"pullAllWithResults: []"
Note how pullAll
and pullAllBy
result in the expected results while pullAllWith
continues to compare everything in arrays
with everything in values
until it ultimately pulls everything.
Metadata
Metadata
Assignees
Labels
No labels