Example 1 — Official Subtract
The main sample from the Ramda docs: start at 0 and subtract each number in turn.
const result = R.reduce(R.subtract, 0, [1, 2, 3, 4]);
console.log(result);
// -10 How It Works
- Start. The accumulator begins at the seed
0. - Each step.
R.subtract(acc, value)computesacc - value:0 - 1 = -1,-1 - 2 = -3,-3 - 3 = -6,-6 - 4 = -10. - Carry forward. Every result becomes the
accfor the next item. - Result. After the last item, the final
acc,-10, is returned.
