01 class Array
02 def split(part)
03 num = self.length/part.to_i
04 result = Array.new
05 for row in 0..(part-1)
06 result[row] = self[num*row...num*(row+1)]
07 end
08 result
09 end
10 end
a = [1,2,3,4,5,6,7,8,9]
a.split(3).inspect # => [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
No comments:
Post a Comment