If I have a hash {:one => [1,2,3,4], :two => [6,7,8]} how can I just make an array where Array[0] = [1,6], [1] = [2,7], [2] = [3,8], [3] = [4,nil]“ ?
If I have a hash {:one => [1,2,3,4], :two => [6,7,8]} how can I
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
With zip:
For any number of keys:
However I don’t believe the order of these is guaranteed (because hashes are unordered). You might want to consider a different approach. (As David points out in the comments, Hashes are actually ordered in Ruby 1.9, so this isn’t a concern.)