Skip to content

Instantly share code, notes, and snippets.

@shaneis
Created May 22, 2018 13:39
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/30de389a57e59ce6818a3fc749059a23 to your computer and use it in GitHub Desktop.
Save shaneis/30de389a57e59ce6818a3fc749059a23 to your computer and use it in GitHub Desktop.
scripty from the block
[int]$FizzRunningTotal = 0
[int]$FizzBuzzRunningTotal = 0
[int]$BuzzRunningTotal = 0
# Scriptblocks
$Mod15 = [Scriptblock]::Create('param([int]$Number) $FizzBuzzRunningTotal = $FizzBuzzRunningTotal + $_')
$Mod5 = [Scriptblock]::Create('param([int]$Number) $BuzzRunningTotal = $BuzzRunningTotal + $_')
$Mod3 = [Scriptblock]::Create('param([int]$Number) $FizzRunningTotal = $FizzRunningTotal + $_')
1..15 | ForEach-Object {
switch ($_) {
{ $_ % 15 -eq 0 } {$Mod15.InvokeReturnAsIs($_); break }
{ $_ % 5 -eq 0 } {$Mod5.InvokeReturnAsIs($_); break }
{ $_ % 3 -eq 0 } {$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