Array Chunking

  • array

Write a function that takes an array and chunk size as arguments and returns an array of arrays where each subarray has at most the specified number of elements.

Array Chunking
Examples:
  • chank([1, 2, 3, 4], 2) -> [[1, 2], [3, 4]];
  • chank([1, 2, 3, 4, 5], 2) -> [[1, 2], [3, 4], [5]];
  • chank([1, 2, 3], 1) -> [[1], [2], [3]];

Write your solution

Loading...