Ravendra Kumar
Ravendra Kumar

Reputation: 1082

Convert Array of Array into string Array in efficient way

I have an array

arr=[["Sumit", "where"], ["where", "are"], ["are", "you"]]

and i want to convert

arr=["Sumit where", "where are", "are you"]

how can i do this in efficient way

Upvotes: 0

Views: 75

Answers (2)

Mark
Mark

Reputation: 6394

arr=[["Sumit", "where"], ["where", "are"], ["are", "you"]]  
v = arr.map { |x| x.join(" ") }  
p v 

Upvotes: 2

shweta
shweta

Reputation: 8169

try:

arr=[["Sumit", "where"], ["where", "are"], ["are", "you"]]
arr = arr.map {|i| i.join(' ') }

Upvotes: 0

Related Questions