Example 1 — Day-over-Day Change
Compare each pair of consecutive numbers.
const days = [10, 12, 11, 15];
const changes = [];
for (let i = 0; i < days.length - 1; i++) {
changes.push(days[i + 1] - days[i]);
}
console.log(changes.join(", ")); How It Works
- Pairs. Each index with the next forms a window of 2.
- Subtract. Positive means an increase.
