Merrill, Jason wrote:
 while (--i -(-1)) {


Jason, very interesting way of counting through the array. I haven't see this approach before. Are there any benefits to using (--i -(-i)) in the expression over something like the following?:

while (i--) {

It seems like your loop would need to do two calculations each trip. One for decrementing i and the second for adding 1 to it to keep the number above zero so it returns true. If you decrement i after the condition using i-- instead of before the condition with --i you won't need add 1 to it. Just an idea.

However, as far as I know you're right looping through the array in AS 2.0 is the only way to find the index of an item. You might also want to use === instead of == to do strict comparing so "12" doesn't equal 12. Depends on what you need tho.

One thing I might add to your function is the ability to return -1 instead of undefined when an item isn't found which is more consistent with the String.indexOf method.

Thankfully, in AS 3.0 there is a method to find the index and as fate would have it it's called indexOf(). It returns either the index if found or -1 if not found. You would use it like:

var idx:Number = a.indexOf("d");

Cheers,
-- James


James O'Reilly
www.jamesor.com
_______________________________________________
[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

Reply via email to