Created
July 15, 2023 18:28
-
-
Save AviTsadok/1099bd81fd7193354938556fb6666b7d to your computer and use it in GitHub Desktop.
Filter name double
This file contains 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
public func filterNameHalfLoop(name: String, fromArray collection: [String]) -> [String] { | |
var result: [String] = [] | |
let count = collection.count | |
var index = 0 | |
while index < count { | |
let tempName1 = collection[index] | |
if index + 1 < count { | |
let tempName2 = collection[index + 1] | |
if tempName1 == name { | |
result.append(tempName1) | |
} | |
if tempName2 == name { | |
result.append(tempName2) | |
} | |
} | |
index += 2 | |
} | |
return result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment