Created
August 19, 2015 13:28
-
-
Save JFFail/e52bf82f016bc2055710 to your computer and use it in GitHub Desktop.
Solution To Reddit Daily Programmer #228
This file contains hidden or 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
#https://www.reddit.com/r/dailyprogrammer/comments/3h9pde/20150817_challenge_228_easy_letters_in/ | |
function CheckOrder { | |
param($Word) | |
#Place the word into an array. | |
$charArray = $Word.ToCharArray() | |
$sortedArray = $charArray | Sort-Object | |
#See if they match. | |
$match = $true | |
$reverseMatch = $false | |
for($i = 0; $i -lt $charArray.Count; $i++) { | |
if($charArray[$i] -ne $sortedArray[$i]) | |
{ | |
$match = $false | |
} | |
} | |
#Check for reverse order if they don't match. | |
if(-not $match) { | |
$reverseArray = $charArray | Sort-Object -Descending | |
$reverseMatch = $true | |
for($i = 0; $i -lt $charArray.Count; $i++) { | |
if($charArray[$i] -ne $reverseArray[$i]) { | |
$reverseMatch = $false | |
} | |
} | |
} | |
#Print result. | |
if($match) { | |
Write-Host "$Word IN ORDER" | |
} elseif($reverseMatch) { | |
Write-Host "$WORD REVERSE ORDER" | |
} else { | |
Write-Host "$Word NOT IN ORDER" | |
} | |
} | |
CheckOrder -Word "billowy" | |
CheckOrder -Word "biopsy" | |
CheckOrder -Word "chinos" | |
CheckOrder -Word "defaced" | |
CheckOrder -Word "chintz" | |
CheckOrder -Word "sponged" | |
CheckOrder -Word "bijoux" | |
CheckOrder -Word "abhors" | |
CheckOrder -Word "fiddle" | |
CheckOrder -Word "begins" | |
CheckOrder -Word "chimps" | |
CheckOrder -Word "wronged" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment