PowerShell - leap, raindrops, reverse-string, two-fer

This commit is contained in:
Xevion
2021-11-26 02:28:45 -06:00
parent e02f2ceabf
commit 3bd08f4c92
29 changed files with 569 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
Function Get-Raindrops() {
<#
.SYNOPSIS
Given a number convert it to Pling, Plang, Plong if it has factors of 3, 5 or 7.
.DESCRIPTION
Convert a number to a string, the contents of which depend on the number's factors.
- If the number has 3 as a factor, output 'Pling'.
- If the number has 5 as a factor, output 'Plang'.
- If the number has 7 as a factor, output 'Plong'.
- If the number does not have 3, 5, or 7 as a factor, just pass the number's digits straight through.
.PARAMETER Rain
The number to evaluate
.EXAMPLE
Get-Raindrops -Rain 35
This will return PlangPlong as it has factors of 5 and 7
.EXAMPLE
Get-Raindrops -Rain 12121
This will return 12121 as it does not contain factors of 3, 5 or 7 so the value is passed through.
#>
[CmdletBinding()]
Param(
[int]$Rain
)
[String] $result = ""
if ($Rain % 3 -eq 0) { $result += "Pling" }
if ($Rain % 5 -eq 0) { $result += "Plang" }
if ($Rain % 7 -eq 0) { $result += "Plong" }
if ($result.Length -gt 0) { return $result }
return $Rain.ToString()
}