Multiplication tables: Difference between revisions
Content added Content deleted
(→{{header|JavaScript}}: Added ES6 version) |
m (→JS ES6) |
||
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 |
return [ |
||
['x', ...xs], |
|||
concatMap( |
...concatMap( |
||
x => [ |
x => [ |
||
[x, ...concatMap( |
|||
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] |