I have 3 values that I want to compare f, g and h. I have some code to check that they all equal each other and that none of them are null. I\'ve had a look online but could
Write a simple function:
var checkAllArguments = function() {
var len = arguments.length;
var obj;
if(len == 0) {
return true;
} else {
if(arguments[0] == null) {
return false;
} else {
obj = arguments[0];
}
}
for(var i=1; i<len; i++) {
if(arguments[i] == null) {
return false;
}
if(obj == arguments[i]) {
continue;
} else {
return false;
}
}
return true;
}
Now, to check multiple arguments, all you have to do is:
if(checkAllArguments(g, h, f)) {
// Do something
}