value in array?

Is there any shorter way to do this in monkeyc?

if (daysLeft == 365 || daysLeft == 350 || daysLeft == 300 || daysLeft == 250 || daysLeft == 200 || daysLeft == 150) {}

looking for something like if (daysLeft in [150, 200, 250, 300, 350, 365]) {}

Thanks
  • ;ooking for something like if (daysLeft in [150, 200, 250, 300, 350, 365]) {}


    There is really no built-in way to do this that I know of. I really wish that Array had a more complete interface (Dictionary is much more useful in this respect). That said, you can easily write a wrapper function to do it though...

    function find_value(value, array) {

    for (var i = 0; i < array.size(); ++i) {
    if (array== value) {
    return true;
    }
    }

    return false;
    }

    //
    if (find_value(daysLeft, [150, 200, 250, 300, 350, 365])) {
    // do something
    }
    [/code]

    Travis