I have an array of 700 question objects that look like this:
[
{
_id: "5ca3216579a592b0910f70d4"
question: "Who wrote Twilight series of novels?"
answer: "Stephenie Meyer"
category: "Art and Literature"
},
...
]
I also have an array of 3 selected question categories that look like this:
["Art and Literature", "Music", "History"]
What I basically need is 4 random questions of each question category. So:
- 4 random questions of Art and Literature
- 4 random questions of Music
- 4 random questions of History
Ideally I think it would be nice to have the 12 random question id's set in a new array based on these 3 categories so I could send them to my database.
How is this to be done?