I have an array of increasing integers like so: [0, 5, 23, …]. The array is big (> 500T). I have to find all elements larger than an input value x and add 1 to each of them.
I do the following:
extension Array where Element == Int {
func incrementElements(largerThan x: Int) -> [Int] {
return self.map { $0 > x ? $0 + 1 : $0 }
}
}
So far so good. The problem is that this operation must be very fast and mine is too slow. Is there a faster way to do this?