Kronecker product: Difference between revisions
→JS ES6: Changed top level of kprod to concatMap - a little cleaner
m (fix) |
(→JS ES6: Changed top level of kprod to concatMap - a little cleaner) |
||
Line 220:
const concat = xs => [].concat.apply([], xs);
//
const
// 2 or more arguments
// curry :: Function -> Function
const curry = (f, ...args) => {
const go = xs => xs.length >= f.length ? (f.apply(null, xs)) :
function () {
return go(xs.concat([].slice.apply(arguments)));
};
return go([].slice.call(args, 1));
};
// map :: (a -> b) -> [a] -> [b]
Line 241 ⟶ 251:
// kprod :: [[Num]] -> [[Num]] -> [[Num]]
const kprod = (xs, ys) =>
);
// (* n) mapped over each element in a matrix
// f :: [[Num]] -> Num -> [[Num]]
const f = curry((mx, n) =>
// TEST -------------------------------------------------------------------
return unlines(map(rows => unlines(map(show, rows)), [
kprod([
[1, 2],
Line 267 ⟶ 278:
[1, 1, 1, 1]
])
]));
})();</lang>
{{Out}}
|