教程 radash tutorial

cluster

将列表拆分为指定大小的多个列表

基本用法

给定一个项数组和所需的集群大小(n),返回一个数组的数组。每个子数组包含 n(集群大小)个尽可能均匀分割的项。

ts
import { cluster } from 'radash'

const gods = ['Ra', 'Zeus', 'Loki', 'Vishnu', 'Icarus', 'Osiris', 'Thor', 'Apollo', 'Artemis', 'Athena']

cluster(gods, 3)
// => [
//   [ 'Ra', 'Zeus', 'Loki' ],
//   [ 'Vishnu', 'Icarus', 'Osiris' ],
//   ['Thor', 'Apollo', 'Artemis'],
//   ['Athena']
// ]