I have an extension here of the String class in Swift that returns the index of the first letter of a given substring.
Can anybody please help me make it so it will
I know we aren't playing code golf here, but for anyone interested in a functional style one-line implementation that doesn't use var
s or loops, this is another possible solution:
extension String {
func indices(of string: String) -> [Int] {
return indices.reduce([]) { $1.encodedOffset > ($0.last ?? -1) && self[$1...].hasPrefix(string) ? $0 + [$1.encodedOffset] : $0 }
}
}