JS Built-ins
TypeScriptintermediate

Advanced β€” splitEvery<T>

πŸ“– Usage Example
splitEvery([1, 2, 3, 4, 5], 2)   // β†’ [[1, 2], [3, 4], [5]]

splitEvery partitions an array into sub-arrays of a given size, with the last possibly shorter.

Advanced: splitEvery

Challenge: Implement splitEvery<T>(n: number, arr: T[]): T[][] splitting an array into chunks of size n.

splitEvery(2, [1,2,3,4,5])  // β†’ [[1,2],[3,4],[5]]
πŸ’‘ Hints (1)
  • β€’ Same as chunk with swapped argument order.