This works but seems incredibly clumsy. The method in question is streetsInObj, and obj is an object that can have the keys “p”, “f”, “t”, “r” which correspond to streets.all. So I’m just trying to return all of the streets that exist in the object.
define(['underscore'], function (_) {
var streets = {
all: [
{abbrev: "p", name: "Preflop"},
{abbrev: "f", name: "Flop"},
{abbrev: "t", name: "Turn"},
{abbrev: "r", name: "River"}
],
streetsInObj: function(obj) {
self.obj = obj;
streets = [];
_.map(self.all, function(street, obj) {
if(self.obj[street.abbrev]) {
streets.push(street);
}
});
return streets;
}
};
var self = streets;
return self;
});
What about:
That should be fine with only 4 streets. If you had 4000 streets, and the object was likely to have far fewer, you could probably gain some speed by starting with an object of streets, like:
and then doing: