Juraj Kirchheim
unread,Aug 14, 2013, 9:02:49 AM8/14/13Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to haxe...@googlegroups.com
To calculate a sum:
Lambda.fold(someArray, function (item, sum) return item + sum, 0);
Or more a bit nicer to read:
using Lambda;
someArray.fold(function (item, sum) return item + sum, 0);
Or the obvious way to do it:
var sum = 0;
for (item in someArray) sum += item;
I often have the impression that these "functional" array methods are
totally overused in JavaScript and the main reason for that is the
rather antiquated C-style for loop in combination with horrible
variable scoping. The last version is the fastest and also has the
least tokens. And it's also self-explanatory.
So while Lambda will give you what you want to do, I would point out
that not all that is "chic" in JavaScript is necessarily the best
thing to do in Haxe ;)
Regards,
Juraj