Nested array filling well.. but tricky search back

Discussion in 'Ruby' started by Josselin, Sep 24, 2007.

  1. Josselin

    Josselin Guest

    thanks to your help..

    I got a nice nested array

    ALL_CATEGORIES = [[[1, "category1"], [2, "category2"], [3,
    "category3"], [4, "category4"]], [[5, "category5"], [6, "category6"],
    [7, "category7"], [8, "category8"]], [[9, "category9"], [10,
    "category10"], [11, "category11"], [12, "category12"], [13,
    "category13"], [14, "category14"], [15, "category15"]], [[16,
    "category16"], [17, "category17"], [18, "category18"], [19,
    "category19"]], [[20, "category20"], [21, "category21"], [22,
    "category22"]], [[23, "category23"], [24, "category24"], [25,
    "category25"], [26, "category26"], [27, "category27"], [28,
    "category28"]], [[29, "category29"], [30, "category30"], [31,
    "category31"]

    so I can get :
    all categories of first domain
    ALL_CATEGORIES[0] => [[1, "category1"], [2, "category2"], [3,
    "category3"], [4, "category4"]]
    first category of first domain
    ALL_CATEGORIES[0][0] => [1, "category1"]
    category index of first category of first domain
    ALL_CATEGORIES[0][0][0] => 1
    category label of first category of first domain
    ALL_CATEGORIES[0][0][1] => "category1"

    is there any easy way to find back the domain index from the category
    index ? or should I rewrite my array ?

    given category index 5 then domain index would be 1
    I would find it in ALL_CATEGORIES[1] => [[5, "category5"], [6,
    "category6"], [7, "category7"], [8, "category8"]]

    thanks fyh

    joss
     
    Josselin, Sep 24, 2007
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Russ Perry Jr
    Replies:
    2
    Views:
    4,148
    Russ Perry Jr
    Aug 20, 2004
  2. Replies:
    9
    Views:
    538
    CBFalconer
    Apr 25, 2006
  3. Josselin

    Nested array filling bad..

    Josselin, Sep 23, 2007, in forum: Ruby
    Replies:
    4
    Views:
    101
    Josselin
    Sep 24, 2007
  4. Mohsen Pahlevanzadeh
    Replies:
    0
    Views:
    121
    Mohsen Pahlevanzadeh
    Sep 9, 2013
  5. MRAB
    Replies:
    0
    Views:
    119
Loading...

Share This Page