jweinst1
7/13/2015 - 5:38 AM

In Swift, this script uses the last() function to check if the inputted character is equal to the last character in a string.

In Swift, this script uses the last() function to check if the inputted character is equal to the last character in a string.

var str = "Hello, playground"
func checklastletter(word: String, letter: String) ->String {
    if letter == last(word) {
        return true
    } else {
        return false
    }
}
checklastletter(str, "g")