I have a game with 2 players. They are called p1
and p2
. Each turn I have to switch between them. This is what I do now
var currentPlayer = "p1";
var nextPlayer = (currentPlayer === "p1") ? "p2" : "p1";
But is seems not elegant. Is there a way to just get "the other one" out of 2 predefined values.