Skip to content
Permalink
Browse files

Merge pull request #742 from kostya/transpose

Array#transpose
  • Loading branch information
alex committed May 31, 2013
2 parents 9a6d4b7 + 744b6b7 commit 054f9b1fab0b510aec1623305fc97a23e18e9cca
Showing with 18 additions and 7 deletions.
  1. +18 −0 lib-topaz/array.rb
  2. +0 −7 spec/tags/core/array/transpose_tags.txt
@@ -433,4 +433,22 @@ def repeated_permutation(r, &block)
Topaz::Array.repeated_permutation(self, r, &block)
self
end

def transpose
return [] if self.empty?

max = nil
lists = self.map do |ary|
ary = Topaz.convert_type(ary, Array, :to_ary)
max ||= ary.size
raise IndexError.new("element size differs (#{ary.size} should be #{max})") if ary.size != max
ary
end

out = []
max.times do |i|
out << lists.map { |l| l[i] }
end
out
end
end

This file was deleted.

0 comments on commit 054f9b1

Please sign in to comment.