Example 1 — Official: Factorials
The sample from the Ramda docs: multiply as you go and keep every product.
const numbers = [1, 2, 3, 4];
const factorials = R.scan(R.multiply, 1, numbers);
console.log(factorials);
// [1, 1, 2, 6, 24] How It Works
- Seed. The result starts as
[1]. - Multiply.
R.multiplycombines the running value with each number: 1, 2, 6, 24. - Keep each step. Every new value is pushed onto the result.
- Result. Five values for four inputs; the last one,
24, is whatR.reducewould return.
