Skip to content

fork

按条件将数组分割为两个数组

98 bytes
since v12.1.0

使用方法

给定一个项目数组和一个条件,返回两个数组,第一个包含所有通过条件的项目,第二个包含所有未通过条件的项目。

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]]