Created
January 7, 2016 21:34
-
-
Save nathanhillyer/ecad7cc1d6b2b99cd7a9 to your computer and use it in GitHub Desktop.
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
func reverseAndRepeatString(stringToReverse: String, numberOfReverses: Int) -> String { | |
let reversed = transformString(stringToReverse, transformation: { String($0.characters.reverse()) }) | |
return transformString(reversed, transformation: { | |
var repeated = "" | |
for _ in 1...numberOfReverses { | |
repeated += $0 | |
} | |
return repeated | |
}) | |
} | |
func transformString(stringToTransform: String, transformation: (String) -> String) -> String { | |
return transformation(stringToTransform) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment