Skip to content

Instantly share code, notes, and snippets.

@nucleardreamer
Created December 25, 2015 00:38
Show Gist options
  • Save nucleardreamer/34ce41d2800836d35aee to your computer and use it in GitHub Desktop.
Save nucleardreamer/34ce41d2800836d35aee to your computer and use it in GitHub Desktop.
short circuit isvalid function
var _ = require('lodash');
// Iterate through all supplied parameters and check if everyone of them is valid
// Checking is done from left to right and short-circuited. So you can supply parameters
// like obj, obj.key1, obj.key1.subkey1 and obj.key1 will be checked only if obj is valid.
var isValid = function(obj /* obj1, obj2, obj3... */){
var args = Array.prototype.slice.call(arguments);
for (var i=0; i < args.length; i++){
if (_.isUndefined(args[i]) || _.isNull(args[i]) || _.isNaN(args[i])) return false;
}
return true;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment