Function mergeBy

Given two lists of the same type, iterate the first list and replace items matched by the matcher func in the first place.

const gods = [
{
name: 'Zeus',
power: 92
},
{
name: 'Ra',
power: 97
}
]

const newGods = [
{
name: 'Zeus',
power: 100
}
]

mergeBy(gods, newGods, f => f.name) // => [{name: "Zeus" power: 100}, {name: "Ra", power: 97}]
  • Type Parameters

    • T

    Parameters

    • root: readonly T[]
    • others: readonly T[]
    • matcher: ((item: T) => any)
        • (item): any
        • Parameters

          • item: T

          Returns any

    Returns readonly T[]