MCPcopy Create free account
hub / github.com/TanStack/query / chunkArray

Function chunkArray

packages/query-devtools/src/Explorer.tsx:51–63  ·  view source on GitHub ↗

* 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,
)

Source from the content-addressed store, hash-verified

49 * chunkArray(['a','b', 'c', 'd', 'e'], 2) // returns [['a','b'], ['c', 'd'], ['e']]
50 */
51function 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
65const Expander = (props: { expanded: boolean }) => {
66 const theme = useTheme()

Callers 1

ExplorerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected