Skip to content

Instantly share code, notes, and snippets.

@AviTsadok
Created July 15, 2023 18:23
Show Gist options
  • Select an option

  • Save AviTsadok/87cabdffa6d923a8783a079a12e1d117 to your computer and use it in GitHub Desktop.

Select an option

Save AviTsadok/87cabdffa6d923a8783a079a12e1d117 to your computer and use it in GitHub Desktop.
Filter name without iterator
func filterName(name: String,
fromArray collection: [String]) -> [String] {
var result: [String] = []
let indices = collection.indices
var currentIndex = indices.lowerBound
while currentIndex < indices.upperBound {
let tempName = collection[currentIndex]
if tempName == name {
result.append(tempName)
}
currentIndex = indices.index(after: currentIndex)
}
return result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment