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
function Get-FizzBuzz { | |
<# | |
.SYNOPSIS | |
Fizz Buzz function | |
.Description | |
The Fizz Buzz function to find numbers divisible by 3/5 or both | |
.PARAMETER Start | |
Specifies the first number | |
.PARAMETER End | |
Specifies the last number | |
.EXAMPLE | |
PS> Get-FizzBuzz -Start 1 -End 100 | |
With positional parameters specified explicitly | |
.EXAMPLE | |
PS> Get-FizzBuzz 1 100 | |
Without specifying parameters name | |
.EXAMPLE | |
PS> Get-FizzBuzz -Start 1 -End 100 -Verbose | |
A bit detailed output enabled | |
.LINK | |
https://rlevchenko.com | |
#> | |
[CmdletBinding()] | |
param ( | |
[Parameter(Mandatory = $false, Position = 1)] | |
$start = 1, | |
[Parameter (Mandatory = $false, Position = 2)] | |
$end = 100 | |
) | |
$start..$end|Foreach-Object { | |
$output = "" | |
if (($_ % 3 -eq 0) -and ($_ % 5 -eq 0)) { | |
Write-Verbose "Found FizzBuzz..." | |
$output += "FizzBuzz: $PSItem" | |
}#if | |
elseif ($_ % 3 -eq 0) { | |
Write-Verbose "Found Fizz..." | |
$output += "Fizz: $PSItem" | |
}#elseif | |
elseif ($_ % 5 -eq 0) { | |
Write-Verbose "Found Buzz..." | |
$output += "Buzz: $PSItem" | |
}#elseif | |
else { | |
Write-Verbose "Displaying the rest..." | |
Write-Host "OutOfScope: $_" | |
}#else | |
return $output | |
}#foreach | |
}#function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment