2

I'm trying to combine elements from one array with every element from another array, I tried looking for some solutions but I couldn't figure it out.

Take these two arrays for example:

num = [1,2,3]

let = ["a","b","c"]

I want to combine them in order to obtain:

combined = [[1, "a"], [1, "b"], [1, "c"], [2, "a"], [2, "b"], [2, "c"], 
            [3, "a"], [3, "b"], [3, "c"]]
0

1 Answer 1

7

You can use #product:

num = [1,2,3]
let = ["a","b","c"]

num.product let
#=>[[1, "a"], [1, "b"], [1, "c"], [2, "a"], [2, "b"], [2, "c"], [3, "a"], [3, "b"], [3, "c"]]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.