Pascal's triangle: Difference between revisions
Content added Content deleted
(→JS ES6: Updated primitives) |
m (→JS ES6: ( clearer formatting/commenting of main function )) |
||
Line 2,512: | Line 2,512: | ||
const pascal = n => |
const pascal = n => |
||
foldl(a => { |
foldl(a => { |
||
const |
const xs = a.slice(-1)[0]; // Previous row |
||
return append(a, [ |
return append(a, [ |
||
zipWith( |
zipWith( |
||
(a, b) => a + b, |
|||
append([0], xs), |
|||
append(xs, [0]) |
|||
⚫ | |||
]); |
]); |
||
}, [ |
}, [ |
||
[1] |
[1] // Initial seed row |
||
], enumFromTo(1, n - 1)); |
], enumFromTo(1, n - 1)); |
||
⚫ | |||
// GENERIC FUNCTIONS ------------------------------------------------------ |
// GENERIC FUNCTIONS ------------------------------------------------------ |