SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jan 2010
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    group in the array

    Hi!

    I have a two-dimensional array Farr.

    Farr.each{ |i| print i}

    output:
    ["200912-829", 9]
    ["200912-893", 3]
    ["200912-893", 5]
    ["200912-829", 1]
    ["200911-818", 6]
    ["200911-893", 1]
    ["200911-827", 2]

    I'm trying to get another two-dimensional array, which would be the
    grouping of the first elements.
    In SQL it would be so:

    select String, sum(Number)
    from Farr
    group by String

    and the resulting array would:
    ["200912-829", 10]
    ["200912-893", 8]
    ["200911-818", 6]
    ["200911-893", 1]
    ["200911-827", 2]

    Help please.
    I apologize for spelling, English is not my native.

  2. #2
    SitePoint Member
    Join Date
    Jan 2010
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    problem solved
    all thanks
    solution here htt_://www.ruby-forum.com/topic/201633


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •