Ruby - 2D array column to 1D array

Discussion in 'Ruby on Rails' started by Rofellos, Jul 10, 2013.

  1. Rofellos

    Rofellos New Member

    Joined:
    Dec 1, 2010
    Messages:
    7
    Likes Received:
    1
    Trophy Points:
    0
    Occupation:
    **** some girls
    Location:
    Dantes Inferno
    Hello,

    Is there any method to do this without using a loop to collect the values?


    Ex.:
    2D array: array =
    [1] [11] [21] [31] [41]
    [2] [12] [22] [32] [42]
    [3] [13] [23] [33] [43]
    [4] [14] [24] [34] [44]
    [5] [15] [25] [35] [45]
    [6] [16] [26] [36] [46]
    [7] [17] [27] [37] [47]
    [8] [18] [28] [38] [48]
    [9] [19] [29] [39] [49]
    [10] [20] [30] [40] [50]

    To get the second row, it can be done like this array[1]
    return 1D array: [2] [12] [22] [32] [42]

    Is there something like this to get columns?
     
  2. Rofellos

    Rofellos New Member

    Joined:
    Dec 1, 2010
    Messages:
    7
    Likes Received:
    1
    Trophy Points:
    0
    Occupation:
    **** some girls
    Location:
    Dantes Inferno
    Solved:

    To get the first row:
    a[0]

    To get the first column:
    a.transpose[0]
     
    shabbir likes this.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice