Skip to content

fork

Split an array into two arrays by a condition

98 bytes

Usage

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 _ from 'radashi'
const gods = [
{
name: 'Ra',
power: 100,
},
{
name: 'Zeus',
power: 98,
},
{
name: 'Loki',
power: 72,
},
{
name: 'Vishnu',
power: 100,
},
]
const [finalGods, lesserGods] = _.fork(gods, f => f.power > 90) // [[ra, vishnu, zeus], [loki]]