I want to write a game in which, at every turn, random passages are chosen from a pool of available passages. So there are two steps: first I filter the complete passage list to get the pool of passages that are adequate to the current situation; second, I pick a random passage from that pool.
The problem is in the first step.
I have done tests with the underscorejs function _.where and it does what I want.
<% s.passages = [
{name:"I drink", subject:"food"},
{name:"I sleep", subject:"rest"} ];
s.select = _.where( s.passages, {subject:"food"};
%>
This code would correctly pick the first element in the array and store it in s.select. So far so good.
Now my question: how should I change the _.where function to pick an element like this?
{name:"I drink", subject:["food","rest"]},
Instead of having a single subject, the value for that key is an array. So the condition is not subject equals "food", but subject contains "food". How can I write that condition inside _.where?
Thanks!