You can also us the member function for arrays:

function myFunc(param1) {
    if ([2,3,4,5,6].member(param1)) { // is param1 a member of the array?



-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Brandon
Aaron
Sent: Sunday, August 13, 2006 8:51 PM
To: rails-spinoffs@lists.rubyonrails.org
Subject: Re: [Rails-spinoffs] Shorthand for "IN"

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
> Rails-spinoffs@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
>
>
>
_______________________________________________
Rails-spinoffs mailing list
Rails-spinoffs@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs

_______________________________________________
Rails-spinoffs mailing list
Rails-spinoffs@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs

Reply via email to