Essential JavaScript

Button Combo Kata

You are working on a video game, and you need to calculate the base damage from a combo move the player enters on the controller.

You are given a string representing the buttons pressed by the player. These are the possible buttons:

  • A
  • B
  • X
  • Y
  • L
  • R
  • U
  • D

Player input might look like this: AUBDBDAAUXL

The base damage from a combo is equal to the number of buttons the player pressed in a row without pressing the same button twice in a row. Pressing the same button twice in a row ends the combo.

For the above example, the return value should be 7, because after the 7th button was pressed (the A button), that same button was pressed again and broke the combo.

Code Editor