function removeCounter(state: List<number>, action: RemoveCounterAction): List<number> { if(state.isEmpty()) { throw "no counters" } if(action.index >= state.size) { throw "index out of bounds" } if(action.index < 0) { throw "index out of bounds" } return state.remove(action.index) }