Hello Chester,
- yes, it's very good way if array is not changed.
but testNumber method is unnecessary:
// prepare:
var nList_array:Array = new Array(12, 34, 21, 46, 52)
var nList_object:Object = new Object();
for (var i:Number = 0, len:nList_array.length; i<len; i++){
nList_object[nList_array[i]] = true;
}
......
// check
a++
if (!nList_object[a]) {
// do something
}
--
good luck,
iv
CM> Why not throw another option in the mix :)
CM> I think this one is more efficient because it only loops through the
CM> number array once at the beginning... but I'm not an optimization
CM> expert.
CM> // define your array of "bad" numbers
CM> var nList_array:Array = new Array(12, 34, 21, 46, 52)
CM> // create an object with a boolean value for each "bad" number
CM> var nList_object:Object = new Object();
CM> for (var i:Number = 0; i<nList_array.length; i++){
CM> var num:Number = nList_array[i];
CM> nList_object["bad"+num] = false;
CM> }
CM> // create a function to "test" a number;
CM> function testNumber(num:Number):Boolean
CM> {
CM> if (nList_object["bad"+num] === false){
CM> return false;
CM> } else {
CM> return true;
CM> }
CM> }
CM> // Now test it
CM> for (var i:Number = 0; i<100; i++){
CM> if (testNumber(i)){
CM> trace("doing something with "+i);
CM> } else {
CM> trace("BAD NUMBER: "+i);
CM> }
CM> }
CM> On Dec 20, 2006, at 4:42 PM, Eduardo Barbosa wrote:
>> Hi all,
>>
>> given a list of numbers such as: (12, 34, 21, 46, 52 ... )
>>
>> what would be the best way to achieve this:
>>
>> a++;
>>
>> if ( a != 12 && a != 34 && a != 21 && a != 46 && a != 52 ... ) {
>> // do something
>> }
>>
>> Am doing my research and trying out some solutions but i thought
>> that in the
>> meantime someone may have a quick ready answer for this or some
>> good hints.
>>
>> thanks a lot!
>>
>> Eduardo
--
Ivan Dembicki
____________________________________________________________________________
[EMAIL PROTECTED] | |
http://www.design.ru
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com