Quantcast
Channel: Active questions tagged ruby - Stack Overflow
Viewing all articles
Browse latest Browse all 4622

Ruby 2D array transpose without using built in method

$
0
0

I've been stuck on this for a while. As an assignment I need to transpose this 2D array without using the built in transpose method, and without altering the function name / output. I feel like it should be way easier than I'm making it out to be...

class Image def transpose     @array.each_with_index do |row, row_index|      row.each_with_index do |column, col_index|        @array[row_index] = @array[col_index]      end    end   end endimage_transpose = Image.new([[1, 2, 3],[4, 5, 6],[7, 8, 9]])print "Image transpose"putsimage_transpose.output_imageputs "-----"image_transpose.transposeimage_transpose.output_imageputs "-----"

Viewing all articles
Browse latest Browse all 4622


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>