For example, if I have an array like this:
[:open, 1, :open, 2, 3, :close, 4, :close, :open, 5, :close]
I want to get this:
[[1, [2, 3], 4], [5]]
The :open effectively becomes [ and :close becomes ]
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You could probably do this with a stack, but it’s pretty easy to design recursively:
Note that this will destroy your original array. You should
cloneit before passing it in if you want to preserve it.