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

Function chunkArray

packages/query-devtools/src/Explorer.tsx:41–53  ·  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

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

Callers 1

ExplorerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected