Cartesian product of two or more lists: Difference between revisions

→‎Functional JS: n-Ary version - a simpler and more maintainable foldr (using reduceRight)
(→‎Functional JS: Updated n-ary version.)
(→‎Functional JS: n-Ary version - a simpler and more maintainable foldr (using reduceRight))
Line 1,170:
bind(as)(
x => bind(xs)(
a => [[a].concat(x)]
[a].concat(x)
i = xs.length; ]
)
)
)([[]]);
return v; []
} ]);
 
// TEST -------------------------------------------
Line 1,204 ⟶ 1,208:
 
// foldr :: (a -> b -> b) -> b -> [a] -> b
const foldr = f => a => xs => {
letxs.reduceRight((a, vx) => f(x)(a), a);
i = xs.length;
while (i--) v = f(xs[i])(v);
return v;
};
 
// intercalate :: String -> [a] -> String
9,659

edits