11 lignes
364 B
TypeScript
11 lignes
364 B
TypeScript
export function partition<T>(array: T[]|undefined, entriesPerRow: number): T[][] {
|
|
return array ? array.reduce((accumulator: T[][], current: T, index) => {
|
|
if (index % entriesPerRow == 0) {
|
|
accumulator[accumulator.length] = [current]
|
|
} else {
|
|
accumulator[accumulator.length - 1]
|
|
}
|
|
return accumulator
|
|
}, []) : []
|
|
}
|