Skip to content

Instantly share code, notes, and snippets.

@shaneis

shaneis/Leaner.ps1

Created May 23, 2018
Embed
What would you like to do?
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
You can’t perform that action at this time.