0

I am working on the rails application I have the following array

["194K-001", "177K-STB", "17SH-LW9", "115L-T03"]

and i want to create it as follow

[["194K-001"], ["177K-STB"], ["17SH-LW9"], ["115L-T03"]]

Thanks

2 Answers 2

3

In IRB:

2.0.0-p0 :001 > ["194K-001", "177K-STB", "17SH-LW9", "115L-T03"].map{|a| [a]}
 => [["194K-001"], ["177K-STB"], ["17SH-LW9"], ["115L-T03"]]
Sign up to request clarification or add additional context in comments.

Comments

3

You can use zip without argument:

["194K-001", "177K-STB", "17SH-LW9", "115L-T03"].zip
# => [["194K-001"], ["177K-STB"], ["17SH-LW9"], ["115L-T03"]]

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.