Skip to main content

Checkpoint: runs count once

Challenge on lesson: Checkpoint: compose under contract

CHALLENGE
Difficulty: intermediate+25 XP

Upgrade the broken compress: sum elements, but each RUN of equal adjacent elements counts once ({2,2,5,5,5,1} โ†’ 8). The broken version sums every element (15). Compare each element with its predecessor โ€” one extra condition in the loop body is enough.

Back to lesson: Checkpoint: compose under contract