Given an array of items and a condition, returns two arrays where the first contains all items that passed the condition and the second contains all items that failed the condition.
import*as
import _
_from'radashi'
const
constgods: {
name:string;
power:number;
}[]
gods= [
{
name: string
name: 'Ra',
power: number
power: 100,
},
{
name: string
name: 'Zeus',
power: number
power: 98,
},
{
name: string
name: 'Loki',
power: number
power: 72,
},
{
name: string
name: 'Vishnu',
power: number
power: 100,
},
]
const [
constfinalGods: {
name:string;
power:number;
}[]
finalGods,
constlesserGods: {
name:string;
power:number;
}[]
lesserGods] =
import _
_.
fork<{
name:string;
power:number;
}>(array:readonly {
name:string;
power:number;
}[], condition: (item: {
name:string;
power:number;
}) =>boolean): [{
name:string;
power:number;
}[], {
name:string;
power:number;
}[]]
export fork
Split an array into two array based on a true/false condition
function.