parallel map and dot product

Brendan Eich brendan at mozilla.com
Thu Apr 4 13:33:49 PDT 2013


Hudson, Rick wrote:
>
> In this case it is the same as with a normal array.
>
> function dotProduct(v1, v2) {
>
> return v1.map(function (e, i) {return e*v2[i];}).reduce(function (a, 
> b) {return a+b;});
>
> }
>

So much nicer with ES6 arrow functions (now in SpiderMonkey):

function dotProduct(v1, v2) {
     return v1.map((e, i) => e * v2[i]).reduce((a, b) => a + b);

}


/be


More information about the es-discuss mailing list