* Chunk elements in the array by size. * * When the array cannot be chunked evenly by size, the last chunk will be * filled with the remaining elements. * @param array - The elements to chunk. * @param size - The number of elements per chunk. Below `1`, no chunks are returned. * @returns The c
( array: Array<T>, size: number, )
| 49 | * chunkArray(['a','b', 'c', 'd', 'e'], 2) // returns [['a','b'], ['c', 'd'], ['e']] |
| 50 | */ |
| 51 | function chunkArray<T extends { label: string; value: unknown }>( |
| 52 | array: Array<T>, |
| 53 | size: number, |
| 54 | ): Array<Array<T>> { |
| 55 | if (size < 1) return [] |
| 56 | let i = 0 |
| 57 | const result: Array<Array<T>> = [] |
| 58 | while (i < array.length) { |
| 59 | result.push(array.slice(i, i + size)) |
| 60 | i = i + size |
| 61 | } |
| 62 | return result |
| 63 | } |
| 64 | |
| 65 | const Expander = (props: { expanded: boolean }) => { |
| 66 | const theme = useTheme() |