Skip to content

Commit

Permalink
Add script
Browse files Browse the repository at this point in the history
  • Loading branch information
SamErde committed Dec 16, 2024
1 parent 180a10d commit 27f93ff
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions General/Test-IsPalindrome.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
function Test-IsPalindrome {
<#
.SYNOPSIS
Test a string to see if it is a palindrome.
.DESCRIPTION
This function tests a string to see if it is a palindrome. A palindrome is a word, phrase, number, or other sequence of characters that reads the same forward and backward.
.PARAMETER String
The string to test.
.EXAMPLE
Test-IsPalindrome -String "racecar"
The string "racecar" is a palindrome, so the function returns $true.
.EXAMPLE
'() ()' | Test-IsPalindrome
The string "() ()" is not a palindrome, so the function returns $false.
.EXAMPLE
'() )(' | Test-IsPalindrome
The string "() )(" is a palindrome, so the function returns $true.
#>
[CmdletBinding()]
[OutputType([bool])]
param (
# The string to test
[Parameter(Mandatory, Position = 0, ValueFromPipeline)]
[ValidateNotNullOrEmpty()]
[string]
$String
)

process {
$ReversedString = -join ($String.ToLower().ToCharArray() | ForEach-Object { $_ })[-1.. - ($String.Length)]
"`n$String || $ReversedString" | Write-Verbose
$Result = $String -eq $ReversedString
}

end {
$Result
}
}

0 comments on commit 27f93ff

Please sign in to comment.