Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zabirauf/c1dfe21715705d74586841243b038e4d to your computer and use it in GitHub Desktop.
Save zabirauf/c1dfe21715705d74586841243b038e4d to your computer and use it in GitHub Desktop.
interface TrafficLight {
red: boolean;
yellow: boolean;
green: boolean;
}
function nextTrafficLightState(
trafficLight: TrafficLight): TrafficLight {
if (trafficLight.red && trafficLight.yellow) {
return { red: false, yellow: false, green: true };
} else if (trafficLight.red) {
return { red: true, yellow: true, green: false };
} else if (trafficLight.yellow) {
return { red: true, yellow: false, green: false };
} else if (trafficLight.green) {
return { red: false, yellow: true, green: false };
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment