← Back to challenges

Sum Consecutive Integers

JavaScriptHardarraysnumbersmath

Instructions

Create a function that takes an array of integers (positive / negative) and return the sum of the numbers that repeat consecutively (return your result as an array).

Examples

sumConsecutives([0, 7, 7, 7, 5, 4, 9, 9, 0]) ➞ [0, 21, 5, 4, 18, 0]

sumConsecutives([4, 4, 5, 6, 8, 8, 8]) ➞ [8, 5, 6, 24]

sumConsecutives([-5, -5, 7, 7, 12, 0]) ➞ [-10, 14, 12, 0]

Notes

N/A

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.