Sum Consecutive Integers

Published by Helen Yu in

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

Watch a quick demo on how Edabit works.