[FlashCodersNY] array math

Hudson Ansley hudsonansley at gmail.com
Wed May 13 06:00:27 PDT 2009


ah, that's a good point, obviously I missed that from the original
email. I would still prefer the less simple but easier to understand
version using total(), but I have a strong preference for
self-documenting code. Also, I was prompted to re-write your valueOf
function because it has an error in it, just in case that is what you
are using and not just an email typo... and since it might be
confusing to others following this thread (if anyone is still there
after the dive down the functional programming rabbit hole ;-)

>      for(var i:uint=0;i<this[i];i++) total+=this[i];
should be

      for(var i:uint=0;i<this.length;i++) total+=this[i];



Regards,
Hudson

On Wed, May 13, 2009 at 8:31 AM, Gregory Gritmon <ggritmon at gmail.com> wrote:
> The topic has gotten way more complicated than it originally was. The reason
> I recommended valueOf is because that is a built-in method invoked
> automatically by Flash when you reference a class as a value.
>
> If you define the method as 'total', it would look something like:
> myTotal = 13+2+MyClass.total()
>
> If you define the method as 'valueOf', it' simply
> myTotal = 13+2+MyClass
>
> ~Greg
>
> Hudson Ansley wrote:
>> this would be faster, and it would work ;-) Also, seems like total
>> would be a better choice than valueOf, but maybe that's just me...
>>
>>     public function total():Number
>>     {
>>        var total:Number=0;
>>        var i:int = this.length;
>>        while (i--) total+=this[i];
>>        return total;
>>     }
> _______________________________________________
> FlashCodersNY mailing list
> FlashCodersNY at flashcodersny.org
> http://mail.flashcodersny.org/mailman/listinfo/flashcodersny_flashcodersny.org
>
>



More information about the FlashCodersNY mailing list