Created
July 15, 2023 18:23
-
-
Save AviTsadok/87cabdffa6d923a8783a079a12e1d117 to your computer and use it in GitHub Desktop.
Filter name without iterator
This file contains hidden or 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
| 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