More efficient way to execute this javascript code

I put together something for my work but I’ve realized that it may be rather hacky. I’ve got a bunch of instances of the same function (with different arguments) sequenced in a while loop that return 1 or 0 depending on a number of conditions, and if the function returns 1, I break out of the loop, like so:

while (!condition) {
   if (this_function(arg0, arg1) > 0) break;
   if (this_function(arg2, arg3) > 0) break;
   if (this_function(arg4, arg5) > 0) break;
   if (this_function(arg6, arg7) > 0) break;
   if (this_function(arg8, arg9) > 0) break;
   if (this_function(arg10, arg11) > 0) break;
   break;
}

Basically, I want the code to continue executing until one of those functions returns 1, and if none of them do, then to stop completely. There surely is a better/cleaner way to do this, I just can’t seem to rack my brain around how. I am just completely overthinking this? Guard clauses perhaps? If anybody has any suggestions, please let me know.

Leave a Comment