You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 14, 2025. It is now read-only.
Repository navigation
This repository was archived by the owner on Jan 14, 2025. It is now read-only.
Surprisingly nobody (at NDC or in YT comments) has challenged Bill who at offset 44:48 & 45:40 declared victory with this solution
public decimal PeakTimePremium(DateTime timeOfToll, bool inbound) =>
(IsWeekDay(timeOfToll), GetTimeBand(timeOfToll), inbound) switch
{
(true, TimeBand.MorningRush, true) => 2.00m,
(true, TimeBand.EveningRush, false) => 2.00m,
(true, TimeBand.MorningRush, false) => 1.00m,
(true, TimeBand.EveningRush, true) => 1.00m,
(true, TimeBand.Daytime, _) => 1.50m,
(true, TimeBand.Overnight, _) => 0.75m,
(false, _, _) => 1.00m,
};
and the MS docs show very similar at https://github.com/dotnet/try-samples/blob/master/csharp8/patterns-peakpricing.md
For goodness sake please refactor the explicit special conditions first and then drop through to the simple default 1.0m result
public decimal PeakTimePremium(DateTime timeOfToll, bool inbound) =>
(IsWeekDay(timeOfToll), GetTimeBand(timeOfToll), inbound) switch
{
(true, TimeBand.MorningRush, true) => 2.00m,
(true, TimeBand.EveningRush, false) => 2.00m,
(true, TimeBand.Daytime, _) => 1.50m,
(true, TimeBand.Overnight, ) => 0.75m,
(, _, _) => 1.00m
};
which matches the special cases and dangling default (else) acts as catch-all for the rest. This distils the spaghetti 50 lines to an even simpler (and clearer) conclusion.
P.S. Don't declare victory too early (didn't we learn that from Gulf War-1?)
PPS see attached graphic for those who think better visually WagnerVille.xlsx
Activity