Skip to content

Instantly share code, notes, and snippets.

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 skywalkw3r/33c7a8e3f71b7af9f5f57c598e6aa231 to your computer and use it in GitHub Desktop.
Save skywalkw3r/33c7a8e3f71b7af9f5f57c598e6aa231 to your computer and use it in GitHub Desktop.
function Get-Fahrenheit {
[CmdletBinding()]
Param(
[Parameter(ValueFromPipeline=$true,
Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[ValidatePattern('^(\d*\.)?\d+$')]
[decimal]$CelsiusTemp
)
[PSCustomObject]@{
Fahrenheit = "$(($CelsiusTemp*1.8)+32)"
Celsius = "$CelsiusTemp"
}
}
function Get-Celsius {
[CmdletBinding()]
Param(
[Parameter(ValueFromPipeline=$true,
Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[ValidatePattern('^(\d*\.)?\d+$')]
[decimal]$FahrenheitTemp
)
[PSCustomObject]@{
Celsius = "$(($FahrenheitTemp-32)/1.8)"
Fahrenheit = "$FahrenheitTemp"
}
}
@thedavecarroll
Copy link

Feel free to check out my response to the challenge.
https://gist.github.com/thedavecarroll/458429ec442b109ea8d6ba46b9ed7b18

Regarding your solution, here's a couple notes:

  • Consider allowing negative temperatures. Though it wasn't explicit, many times you will be given incomplete (or assumed) requirements.
  • Also, consider looking at Get-Verb to help pick the verb to use for best practice. Convert, ConvertFrom, and ConvertTo from the Data group seems to be the best choice, in my opinion.
  • Cool (pun intended) that we both settled on [decimal] type.
  • Looks like you figured out the pipeline input. Kudos.

These challenges are fun. I hope you think so, too.

Thanks for your submission. I'm sure the Chairman is pleased. :)

@skywalkw3r
Copy link
Author

Thanks for the feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment