Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9247977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:52:03+00:00 2026-06-18T09:52:03+00:00

Possible Duplicate: ruby – Permutation between elements of an array I’m coding a plugin

  • 0

Possible Duplicate:
ruby – Permutation between elements of an array

I’m coding a plugin in Google Sketchup with ruby and I faced a real problem while trying to permute different elements in arrays that are present in an another array, all this depending on a user combination.

I have an array of arrays like:

[["a, "b", c"], ["lol1", "lol2", lol3"], ["so1", "so2", "so3"]]

For a combination like:

[1, 2, 3]

The output should still same:

[["a", "b", "c"], ["lol1", "lol2", "lol3"], ["so1", "so2", "so3"]]

But for a combination like:

[2, 1, 3]

The output should be:

[["b", "a", "c"], ["lol2", "lol1", "lol3"], ["so2", "so1", "so3"]]

But for a combination like:

[3, 2, 1]

The output should be:

[["c", "b", a"], ["lol3", "lol2", "lol1"], ["so3", "so2", "so1"]]
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T09:52:03+00:00Added an answer on June 18, 2026 at 9:52 am
    ar = [["a, b, c"], ["lol1, lol2, lol3"], ["so1, so2, so3"]]
    p maybe_this = ar.map{|sub_ar| sub_ar.first.split(', ')}
    #[["a", "b", "c"], ["lol1", "lol2", "lol3"], ["so1", "so2", "so3"]]
    idx = [2,1,3]
    #indexing of an array is zero-based
    p idx.map!{|i| i-1} #[1,0,2]
    p res = maybe_this.map{|sub_ar| sub_ar.values_at(*idx)}
    #[["b", "a", "c"], ["lol2", "lol1", "lol3"], ["so2", "so1", "so3"]]
    

    The short story: the values_at method takes multiple arguments; *idx splats an array into multiple arguments.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: count duplicate elements in ruby array I just started learning ruby and
Possible Duplicate: How to split (chunk) a Ruby array into parts of X elements?
Possible Duplicate: Ruby: difference between || and ‘or’ Using Ruby || and or are
Possible Duplicate: Array slicing in Ruby: looking for explanation for illogical behaviour (taken from
Possible Duplicate: Ruby’s double colon (::) operator usage differences I've made a font-awesome plugin
Possible Duplicate: Array slicing in Ruby: looking for explanation for illogical behaviour (taken from
Possible Duplicate: check if value exists in array in Ruby I have this method
Possible Duplicate: Ruby: difference between || and 'or' In ruby, isn't 'or' and '||'
Possible Duplicate: Ruby - What is the difference between map, each and collect? I
Possible Duplicate: Ruby on Rails Callback, what is difference between :before_save and :before_create? I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.