Skip to content

Instantly share code, notes, and snippets.

@darrarski
Created November 22, 2017 19:55
Show Gist options
  • Save darrarski/2a786e1cc34fe416482eaf0288873154 to your computer and use it in GitHub Desktop.
Save darrarski/2a786e1cc34fe416482eaf0288873154 to your computer and use it in GitHub Desktop.
extension String {
/// For "TEST" returns ["T", "TE", "TES", "TEST"]
var keystrokeSubsequences: [String] {
let start = distance(from: startIndex, to: startIndex)
let end = distance(from: startIndex, to: endIndex)
return (start...end).map { index in
let substringEnd = self.index(startIndex, offsetBy: index)
let substring = self[..<substringEnd]
return String(substring)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment