-
Write a
partition
method that takes alist
andsize
parameters and returns a list of sublists, where each sublist has at mostsize
elements.Example inputs and outputs:
- Example 1:
partition([1,2,3,4,5], 2)
returns:[ [1,2], [3,4], [5] ]
- Example 2:
partition([1,2,3,4,5], 3)
returns:[ [1,2,3], [4,5] ]
- Example 1:
- Example 3:
partition([1,2,3,4,5], 1)
returns:[ [1], [2], [3], [4], [5] ]