Skip to content

Instantly share code, notes, and snippets.

@AviTsadok
Created July 15, 2023 18:28
Show Gist options
  • Save AviTsadok/1099bd81fd7193354938556fb6666b7d to your computer and use it in GitHub Desktop.
Save AviTsadok/1099bd81fd7193354938556fb6666b7d to your computer and use it in GitHub Desktop.
Filter name double
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