3

I want to convert this array

[[["b", "c"], ["c", "d"]], [["v", "e"], ["r", "g"]]]

into

[["b", "c"], ["c", "d"], ["v", "e"], ["r", "g"]]

How can I convert this ?

2 Answers 2

13

Array#flatten takes an optional level:

The optional level argument determines the level of recursion to flatten

Example:

[[["b", "c"], ["c", "d"]], [["v", "e"], ["r", "g"]]].flatten(1)
#=> => [["b", "c"], ["c", "d"], ["v", "e"], ["r", "g"]]
Sign up to request clarification or add additional context in comments.

Comments

0
arr = []
a = [[["b", "c"], ["c", "d"]], [["v", "e"], ["r", "g"]]]
a.map{|x| x.map{|y| arr << y}}
puts arr

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.