what is the best idiom to perform the opposite of "zip"? (besides "unfold")

Discussion in 'Ruby' started by bwv549, Oct 2, 2012.

  1. bwv549

    bwv549 Guest

    I need to turn some list of pairs into two arrays (the opposite of zipping two arrays together). There is a solution using "unfold" here (http://weblog.raganwald.com/2007/11/really-useful-anamorphisms-in-ruby.html) but that seems like more than what I want for this task.

    I want to turn this:
    [[1,2][3,4],[5,6]]

    Into:
    [[1,3,5], [2,4,6]]

    What's the best ruby idiom for doing this task. Can it be generalized for triplets, quadruplets, etc.?

    Or, if you use unfold, is there a particular gem you use and does it take amajor performance hit?
     
    bwv549, Oct 2, 2012
    #1
    1. Advertisements

  2. bwv549

    bwv549 Guest

    Array#transpose

    And I've used and recommended this many times...
     
    bwv549, Oct 2, 2012
    #2
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.