PowerShell, 154 , 152 , 99 , 86 Byte
Vielen Dank an @TimmyD, dass du mir satte 47 Bytes gespart hast (ich habe auch weitere 6 Bytes gespart)
Vielen Dank an @TessellatingHeckler, dass Sie weitere 13 Byte gespeichert haben.
Neueste:
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''
Normale Formatierung:
Neueste (sieht meiner Meinung nach am besten aus als zwei Zeilen):
param($a)
-join($a[$a.length..0] | %{("$_".ToLower(), "$_".ToUpper())[$a[$i++] -in 65..90]})
Erläuterung:
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 ''
Das erste Mal Poster hier, war motiviert, weil ich selten PowerShell sehe, aber bei 154 152 Bytes auf diesem ... Ich kann verstehen, warum! Anregungen geschätzt.
Ich habe gelernt, dass ich meine Denkweise auf Golf in Code und dessen Spaß komplett umstellen muss!