Created
March 8, 2018 17:42
-
-
Save kevinjstewart/2ee2a8d28232da89f5739bd7c5b967d8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
extension String { | |
func pyramid() -> String { | |
var result = "" | |
for index in 1..<characters.count { | |
result.append(contentsOf: self.characters.prefix(index)) | |
result.append("\n") | |
} | |
for index in stride(from: characters.count, to: 0, by: -1) { | |
result.append(contentsOf: self.characters.prefix(index)) | |
result.append("\n") | |
} | |
return result | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment