Skip to content

Instantly share code, notes, and snippets.

@kevinjstewart
Created March 8, 2018 17:42
Show Gist options
  • Save kevinjstewart/2ee2a8d28232da89f5739bd7c5b967d8 to your computer and use it in GitHub Desktop.
Save kevinjstewart/2ee2a8d28232da89f5739bd7c5b967d8 to your computer and use it in GitHub Desktop.
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