mirror of
https://github.com/zhigang1992/react-native-super-grid.git
synced 2026-01-12 22:50:58 +08:00
15 lines
367 B
JavaScript
15 lines
367 B
JavaScript
// eslint-disable-next-line import/prefer-default-export
|
|
export function chunkArray(array, size) {
|
|
if (array == []) return [];
|
|
return array.reduce((acc, val) => {
|
|
if (acc.length === 0) acc.push([]);
|
|
const last = acc[acc.length - 1];
|
|
if (last.length < size) {
|
|
last.push(val);
|
|
} else {
|
|
acc.push([val]);
|
|
}
|
|
return acc;
|
|
}, []);
|
|
}
|