0

I have this array:

parsed_data = ["Mike Henry,7/7/87,Oakland,831 123-2758", "David Jordan,12/30/92,Bangkok,831 229-1234", "Matt Rosen,5/21/89,Seattle,925 518-9933"]

I would like to convert it to:

[["Mike Henry", "7/7/87", "Oakland", "831 123-2758"],["David Jordan", "12/30/92", "Bangkok", "831 229-1234"],["Matt Rosen", "5/21/89", "Seattle", "925 518-9933"]]

I have tried

parsed_data = parsed_data.each do |file|
  file.split(",")
end

but it returns my original array. Any help is greatly appreciated!

1

1 Answer 1

5

You should use Enumerable#map, because Enumerable#each will just iterate through the items, but #map will create a new array from the return value of the block:

parsed_data.map { |data| data.split(',') }
Sign up to request clarification or add additional context in comments.

1 Comment

ahh I totally forgot how to use map. Thanks a lot!

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.