I have an array:
[{
"name": "Category 1",
"entries": [{
"question": "Question 1",
"answer": "Answer 1"
}, {
"question": "Question 2",
"answer": "Answer 2"
}, {
"question": "Question 3",
"answer": "Answer 3"
}]
}, {
"name": "Category 2",
"entries": [{
"question": "Question 1",
"answer": "Answer 1"
}, {
"question": "Question 2",
"answer": "Answer 2"
}, {
"question": "Question 3",
"answer": "Answer 3"
}]
}]
What I want to do is create a new array of just the entries.
So I end up with this:
[{
"question": "Question 1",
"answer": "Answer 1"
}, {
"question": "Question 2",
"answer": "Answer 2"
}, {
"question": "Question 3",
"answer": "Answer 3"
}, {
"question": "Question 1",
"answer": "Answer 1"
}, {
"question": "Question 2",
"answer": "Answer 2"
}, {
"question": "Question 3",
"answer": "Answer 3"
}]
In PHP I would of just do a push into a new array... but in Ruby is it possible to use group_by or collect to achieve this?
arr = [{ "name": "Category 1",...]). That way, readers can refer to the variable(s) (arr) in answers and comments without having to define it (them), and all readers will use the same variable(s). I suggest you edit your question to do that. Generally there's no need to do that for desired or expected output objects.