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

Function chunkArray

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

47 * chunkArray(['a','b', 'c', 'd', 'e'], 2) // returns [['a','b'], ['c', 'd'], ['e']]
48 */
49function chunkArray<T extends { label: string; value: unknown }>(
50 array: Array<T>,
51 size: number,
52): Array<Array<T>> {
53 if (size < 1) return []
54 let i = 0
55 const result: Array<Array<T>> = []
56 while (i < array.length) {
57 result.push(array.slice(i, i + size))
58 i = i + size
59 }
60 return result
61}
62
63const Expander = (props: { expanded: boolean }) => {
64 return (

Callers 1

ExplorerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected