Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //swift
- //demonstrating a function that returns another function as its value
- func addALetter() -> (String -> String) {
- func addChars(char: String) -> String {
- var twoChars = ""
- var newChar = ""
- if char == "z" {
- newChar = "zy"
- } else {
- let alphabet = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y", "z"]
- let count = alphabet.count
- for i in 0..count {
- if char == alphabet[i] {
- twoChars = alphabet[i+1]
- newChar = char + twoChars
- }
- }
- }
- return newChar
- }
- return addChars
- }
- //let f = "g"
- var s = addALetter()
- s("c")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement