Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@shaneis
Created May 23, 2018 11:01
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 shaneis/1071c6b763181b33321d3b24ed67ec49 to your computer and use it in GitHub Desktop.
Save shaneis/1071c6b763181b33321d3b24ed67ec49 to your computer and use it in GitHub Desktop.
Moved the modulus check into the scriptblock
[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