The following was proposed as a logical AND/OR multi-arg Handlebars.JS helper:
Handlebars.registerHelper({
and: function () {
return Array.prototype.slice.call(arguments).every(Boolean);
},
or: function () {
return Array.prototype.slice.call(arguments).some(Boolean);
}
});
This doesn't work for me because I need to call it as
{{#if (or questionType 'STARTTIME' 'ENDTIME') }}
{{#if (or questionType 'STARTTIME' 'ENDTIME' 'ARGUMENT3' 'ARGUMENT4') }}
In other words,
- I support multiple args for my AND/OR,
The first arg is always what I'm checking, e.g.
return (questionType == arg1 || questionType == arg2 || questionType == arg3 ...)
In other words, I can't write a dumb 2-param or(..) / and(..) like this,
Handlebars.registerHelper('or', function(a, b, c) {
if(a == b || a == c)
return true;
else
return false;
});
It should be multi-argument, with the first one always being checked. Any thoughts?