I have a function with a bunch of arguments, and I just want to check if any of them are falsy (empty, undefined, null, etc.).
One option is obvious to just check every argument individually, but it's pretty repetitive:
if not arg1
response.send 400, 'Missing argument arg1'
if not arg2
response.send 400, 'Missing argument arg2'
I can simplify that a bit with this, but I still have to list out every every argument and argument name:
for key, value of { 'arg1': arg1, 'arg2': arg2 }
if not value
response.send 400, "Missing argument #{key}"
I was hoping to do something like this:
for key, value of arguments
if not value
response.send 400, "Missing argument #{key}"
But arguments
is more like an array. Is there a way to get the arguments as an object, or get the argument names as an array? Am I going about this this wrong way?
What is a good way of validating a bunch of arguments without repeating myself?