Created
July 13, 2015 19:27
-
-
Save jweinst1/bacf35f221688d4635b1 to your computer and use it in GitHub Desktop.
In Swift, Takes a string and returns the nth character from the end, where 0 is the last character in the string.
This file contains 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
// Takes a string and returns the nth character from the end, where 0 is the last character in the string. | |
func reversestrindex(str: String, index: Int) ->Character { | |
var reversedstrArray = Array(reverse(str)) | |
return reversedstrArray[index] | |
} | |
reversestrindex("power", 2) | |
// "w" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment