Created
December 25, 2015 00:38
-
-
Save nucleardreamer/34ce41d2800836d35aee to your computer and use it in GitHub Desktop.
short circuit isvalid function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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