Created
May 22, 2018 16:38
-
-
Save shaneis/50994abbdf82e6fa220f7cad52763acd to your computer and use it in GitHub Desktop.
...or another...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[int]$FizzRunningTotal = 0 | |
[int]$FizzBuzzRunningTotal = 0 | |
[int]$BuzzRunningTotal = 0 | |
$Mod15 = [Scriptblock]::Create('param([int]$Number) $FizzBuzzRunningTotal + $_ ') | |
$Mod5 = [Scriptblock]::Create('param([int]$Number) $BuzzRunningTotal + $_ ') | |
$Mod3 = [Scriptblock]::Create('param([int]$Number) $FizzRunningTotal + $_ ') | |
1..15 | ForEach-Object { | |
switch ($_) { | |
{ $_ % 15 -eq 0 } { | |
$FizzBuzzRunningTotal = $Mod15.InvokeReturnAsIs($_) | |
break | |
} | |
{ $_ % 5 -eq 0 } { | |
$BuzzRunningTotal = $Mod5.InvokeReturnAsIs($_) | |
break | |
} | |
{ $_ % 3 -eq 0 } { | |
$FizzRunningTotal = $Mod3.InvokeReturnAsIs($_) | |
break | |
} | |
} | |
[PSCustomObject]@{ | |
Number = $_ | |
FizzRunningTotal = $FizzRunningTotal | |
BuzzRunningTotal = $BuzzRunningTotal | |
FizzBuzzRunningTotal = $FizzBuzzRunningTotal | |
} | |
} | Format-Table -AutoSize |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment