Jump to content

Dot product: Difference between revisions

m
m (→‎JS ES6: Tidied)
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;
 
 
9,655

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.