发布时间:2022-07-04 文章分类:编程知识 投稿人:王小丽 字号: 默认 | | 超大 打印

def partition(array, size){
def partitions =[]
int partitionCount = array.size()/ size

partitionCount.times { partitionNumber ->
def start = partitionNumber * size
defend= start + size -1
partitions
<< array[start..end]
}

if(array.size()% size) partitions << array[partitionCount * size..-1]
return partitions
}