11 lines
364 B
TypeScript
11 lines
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
|
||
|
}, []) : []
|
||
|
}
|