0

I want to split arrays in an array and get the string of the second elements mixed.

[["c","a","t"], ["d","o","g"]]
...
# => "ao"

How can I do it? I tried the join method and got the second and the fifth ones. But when the word length is different like this:

[["b","i","r","d"], ["c","a","t"]]

I don't know how to do it. Could you give me some advice?

0

3 Answers 3

5
> ary = [["c","a","t"], ["d","o","g"]]
=> [["c", "a", "t"], ["d", "o", "g"]]
> ary.map{|a| a[1]}.join
=> "ao"
Sign up to request clarification or add additional context in comments.

Comments

4

You could try something like this :

> [["c","a","t"], ["d","o","g"]].collect{|e| e[1]}.join
=> "ao"

Comments

0

Hopefully this will help

a = [["b","i","r","d"], ["c","a","t"]]
result = a.collect{ |_,s,*__| s }.join
p result 
# => "ia"

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.