exercism/elixir/need-for-speed/lib/need_for_speed/race.ex

25 lines
531 B
Elixir
Raw Permalink Normal View History

2024-03-07 05:52:53 +00:00
defmodule NeedForSpeed.Race do
defstruct [
:title,
:total_distance_in_meters,
cars: []
]
def display_status(%NeedForSpeed.Race{} = race) do
cond do
Enum.any?(race.cars, &(&1.distance_driven_in_meters >= race.total_distance_in_meters)) ->
"Finished"
Enum.any?(race.cars, &(&1.distance_driven_in_meters > 0)) ->
"In Progress"
true ->
"Not Started"
end
end
def display_distance(%NeedForSpeed.Race{total_distance_in_meters: d}) do
"#{d} meters"
end
end