Multiplication tables: Difference between revisions

Content added Content deleted
(→‎{{header|JavaScript}}: Added ES6 version)
Line 2,648: Line 2,648:
const multTable = (m, n) => {
const multTable = (m, n) => {
const xs = enumFromToInt(m, n);
const xs = enumFromToInt(m, n);
return cons(
return [
cons('x', xs),
['x', ...xs],
concatMap(
...concatMap(
x => [cons(x, concatMap(
x => [
y => y < x ? [''] : [x * y],
[x, ...concatMap(
xs
y => y < x ? [''] : [x * y],
))],
xs
)]
],
xs
xs
)
)
);
];
};
};


Line 2,696: Line 2,698:
// concatMap :: (a -> [b]) -> [a] -> [b]
// concatMap :: (a -> [b]) -> [a] -> [b]
const concatMap = (f, xs) => [].concat.apply([], xs.map(f));
const concatMap = (f, xs) => [].concat.apply([], xs.map(f));

// cons :: a -> [a] -> [a]
const cons = (x, xs) => [x, ...xs];


// enumFromToInt :: Int -> Int -> [Int]
// enumFromToInt :: Int -> Int -> [Int]