Well you could always use the include function.

function myFunc(param1) {
   if ([2,3,4,5,6].include(param1)) { // is param1 equal to 2, 3, 4, 5 or 6?

the include function is a part of Enumerable.

On 8/10/06, Sam <[EMAIL PROTECTED]> wrote:



Somewhere in a prototype extension library, I noticed a shorthand (can't
find it now) for testing whether an parameter is in a set of values.

The set was in an object or an array (don't remember) and resulted in an
easy shorthand.

Maybe something like:

function myFunc (parm1) {
if( {2:2, 5:5, 9:9, 17:17}[parm1] ) { // Is parm1 equal to 2, 5, 9 or 17?

This seems more verbose that what I recall.

What's a good shorthand technique for testing whether a value is in a set?

Sam


_______________________________________________
Rails-spinoffs mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs



_______________________________________________
Rails-spinoffs mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs

Reply via email to