How can I simplify the following better using Underscore? It feels like too much code for something very simple. It creates a regex from the object keys.
var obj = {
'dog' : 1,
'cat' : 1,
'rat' : 1
};
var arr = [], regex;
_.each( obj, function( value, index ){
arr.push( index );
});
regex = _.reduce( arr, function(){
return new RegExp( arr.join('|'), 'i' );
});
// console.log( regex ) should output:
/dog|cat|rat/i