using this, `newDirectionIndex` might still be neg...
# getting-started
a
using this,
newDirectionIndex
might still be negative. So we’d need to handle that:
Copy code
val modifierForTurn = (if (turn == Turn.R) 1 else -1)
        val currentIndex = directionsInRightTurnOrder.indexOf(heading)

        var nextIndex = (currentIndex + modifierForTurn) % directionsInRightTurnOrder.size
        nextIndex = if (nextIndex < 0) directionsInRightTurnOrder.size + nextIndex else nextIndex
        return directionsInRightTurnOrder[nextIndex]