Currently I’ve got code like this ..
var result = line.match( some regexp );
if (result !== null) {
return callback({ a: 'aaaaa', b: bvariable });
});
}
var result = line.match( some other regexp );
if (result !== null) {
return callback({ d: 'ddddd', c: bvariable });
});
}
I have about 10 of these all with different RegExps and callbacks and the list will get bigger. Is there a better/cleaner way of doing this ?
You can get rid of the result variable
As the match function always returns null or an array, is safe to asume that if the match fails, the null returned will be casted to false, and if the match succeed the array returned (no matter how many elements it have) will be casted to true.