Dot product: Difference between revisions

Content deleted Content added
Hout (talk | contribs)
m →‎JS ES6: Tidied
Hout (talk | contribs)
Line 1,590:
 
===ES6===
Composing functional primitives into a '''dotProduct()''' which returns a '''undefinednull''' value (rather than an error) when the array lengths are unmatched.
 
<syntaxhighlight lang="javascript">(() => {
Line 1,597:
// ------------------- DOT PRODUCT -------------------
 
// dotProduct :: [Num] -> [Num] -> Either Null Num
const dotProduct = xs =>
ys => xs.length === ys.length
? sum(zipWith(mul)(xs)(ys))
: undefinednull;