Array.reduce() ?

    Aug 12 2011 | 7:19 pm
    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 | 6:15 pm
      PS: If Max6 will take care of this issue, that would also be useful to know.
    • Aug 18 2011 | 4:09 pm
      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 | 12:34 pm
      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 04 2011 | 9:45 pm
      Array.reduce() works great in Max 6…
    • Sep 05 2011 | 4:57 pm
      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 06 2011 | 9:32 pm
      according to the announcement it's arriving this fall, that should narrow it down ;-)
    • Sep 07 2011 | 8:12 pm
      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.)