PowerShell, 154, 152, 99, 86 bytes
Thank you @TimmyD for saving me a whopping 47 bytes (I also saved an additional 6)
Thank you @TessellatingHeckler for saving an additional 13 bytes.
Latest:
param($a)-join($a[$a.length..0]|%{("$_".ToLower(),"$_".ToUpper())[$a[$i++]-in65..90]})
Original:
param($a);$x=0;(($a[-1..-$a.length])|%{$_=$_.tostring().tolower();if([regex]::matches($a,"[A-Z]").index-contains$x){$_.toupper()}else{$_};$x++})-join''
Normal formatting:
Latest (looks best as two lines in my opinion):
param($a)
-join($a[$a.length..0] | %{("$_".ToLower(), "$_".ToUpper())[$a[$i++] -in 65..90]})
Explanation:
param($a)-join($a[$a.length..0]|%{("$_".ToLower(),"$_".ToUpper())[$a[$i++]-in65..90]})
param($a)
# Sets the first passed parameter to variable $a
-join( )
# Converts a char array to a string
$a[$a.length..0]
# Reverses $a as a char array
|%{ }
# Shorthand pipe to foreach loop
("$_".ToLower(),"$_".ToUpper())
# Creates an array of the looped char in lower and upper cases
[$a[$i++]-in65..90]
# Resolves to 1 if the current index of $a is upper, which would output "$_".ToUpper() which is index 1 of the previous array
Original:
param($a)
$x = 0
(($a[-1..-$a.length]) | %{
$_ = $_.tostring().tolower()
if([regex]::matches($a,"[A-Z]").index -contains $x){
$_.toupper()
}else{
$_
}
$x++
}
) -join ''
First time poster here, was motivated because I rarely see PowerShell, but at 154 152 bytes on this one... I can see why! Any suggestions appreciated.
I have learned that I must completely change my way of thinking to golf in code and its fun!