mirror of
https://github.com/Xevion/exercism.git
synced 2025-12-14 20:11:39 -06:00
PowerShell - leap, raindrops, reverse-string, two-fer
This commit is contained in:
40
powershell/raindrops/Raindrops.ps1
Normal file
40
powershell/raindrops/Raindrops.ps1
Normal 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()
|
||||
}
|
||||
Reference in New Issue
Block a user