Given two arrays of items and an identity function, returns the first
list with all items from the second list where there was a match.
import*as
import _
_from'radashi'
const
constgods: {
name:string;
power:number;
}[]
gods= [
{
name: string
name: 'Zeus',
power: number
power: 92,
},
{
name: string
name: 'Ra',
power: number
power: 97,
},
]
const
constnewGods: {
name:string;
power:number;
}[]
newGods= [
{
name: string
name: 'Zeus',
power: number
power: 100,
},
]
const
constmergedGods: {
name:string;
power:number;
}[]
mergedGods=
import _
_.
merge<{
name:string;
power:number;
}>(prev:readonly {
name:string;
power:number;
}[], array:readonly {
name:string;
power:number;
}[], toKey: (item: {
name:string;
power:number;
}) =>any): {
name:string;
power:number;
}[]
export merge
Given two arrays of the same type, iterate the first list and
replace items matched by the matcher function in the first place.
The given arrays are never modified.