jweinst1
7/13/2015 - 7:09 PM

Function that can determine whether or not to add a character to a string based on some of the indexes of the string. Swift.

Function that can determine whether or not to add a character to a string based on some of the indexes of the string. Swift.

func indexstring(str: String, index: Int) ->Character {
    var strlist = Array(str)
    return strlist[index]
}

func addconorvow(str: String) ->String {
    var modstr = str
    if indexstring(str, 1) == "d" {
        modstr += "d"
        return modstr
    } else {
        modstr += "e"
        return modstr
    }
    
}