MCPcopy
hub / github.com/TanStack/query / chunkArray

Function chunkArray

packages/query-devtools/src/Explorer.tsx:33–45  ·  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 * * @example * chunkArray(['a','b', 'c', 'd', 'e'], 2) // returns [['a','b'], ['c', 'd'], ['e']]

(
  array: Array<T>,
  size: number,
)

Source from the content-addressed store, hash-verified

31 * chunkArray(['a','b', 'c', 'd', 'e'], 2) // returns [['a','b'], ['c', 'd'], ['e']]
32 */
33function chunkArray<T extends { label: string; value: unknown }>(
34 array: Array<T>,
35 size: number,
36): Array<Array<T>> {
37 if (size < 1) return []
38 let i = 0
39 const result: Array<Array<T>> = []
40 while (i < array.length) {
41 result.push(array.slice(i, i + size))
42 i = i + size
43 }
44 return result
45}
46
47const Expander = (props: { expanded: boolean }) => {
48 const theme = useTheme()

Callers 1

ExplorerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…