Array.reduce() ?

Aug 12, 2011 at 7:19pm

Array.reduce() ?

ECMAScript 5 supports a method for Arrays called reduce().

The [js] object seems not to like this. “js: myJavaScript.js: Javascript TypeError: a.reduce is not a function, line 164″

Yes, the variable a is an array, freshly generated by a call to arrayfromargs(arguments).

I suppose I’ll have to use forEach or [gasp!] a plain-vanilla for loop to get the result I want. Or am I missing something? As in: is there any way to get the js object to grok Array.reduce()?

Most other ECMAScript 5 methods are supported by, so I was a bit surprised about this.

Aug 13, 2011 at 6:15pm

PS: If Max6 will take care of this issue, that would also be useful to know.

Aug 18, 2011 at 4:09pm

Javascript 1.6 (the version Max uses) does not support reduce natively but I don’t see why you couldn’t use a javascript library to add the functionality.
My favourite would be Underscore.js –

I can’t guarantee this will work but I am 99% certain underscore has no reliance on the DOM so it should!

Let us know how you get on :)

Aug 30, 2011 at 12:34pm

OK, I was focusing on the ECMAScript version; ECMAScript 5 introduces all the nifty Array methods. Need to pay more attention to what the different JScript levels support.

Since there is currently only one place in my code where Array.reduce() would have been really nice to have, I’ve simply written a plain-vanilla for loop instead. Nothing against added libraries, but time and place…

Sep 4, 2011 at 9:45pm

Array.reduce() works great in Max 6…

Sep 5, 2011 at 4:57pm

Nice to know. The other question, of course, would be « quand arrive-t-il ? » but I last time I looked there’s no ETA.

Sep 6, 2011 at 9:32pm

according to the announcement it’s arriving this fall, that should narrow it down ;-)

Sep 7, 2011 at 8:12pm

Oh, there it is. Right at the top. Last place I look for that sort of thing. C’est ma faute.

Later down I see we’re up to JS 1.8.5. Yummy. (Yes, I know, I used to be disdainful about the language. I still think automatic variable declaration is an absolutely execrable design decision, but there is a lot about the language to like.)


You must be logged in to reply to this topic.