Created
May 23, 2018 11:01
-
-
Save shaneis/1071c6b763181b33321d3b24ed67ec49 to your computer and use it in GitHub Desktop.
Moved the modulus check into the scriptblock
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) if ($Number % 15 -eq 0) { $FizzBuzzRunningTotal + $_ }') | |
$Mod5 = [Scriptblock]::Create('param([int]$Number) if ($Number % 5 -eq 0) { $BuzzRunningTotal + $_ }') | |
$Mod3 = [Scriptblock]::Create('param([int]$Number) if ($Number % 3 -eq 0) { $FizzRunningTotal + $_ }') | |
1..15 | ForEach-Object { | |
$FizzRunningTotal = $Mod3.InvokeReturnAsIs($_) | |
$BuzzRunningTotal = $Mod5.InvokeReturnAsIs($_) | |
$FizzBuzzRunningTotal = $Mod15.InvokeReturnAsIs($_) | |
[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