Ch. 21, Generics, Gold Challenge

   func findAll<T: Collection, U: Equatable>(_ collection: T, _ item: U) -> [Int] where T.Element == U {
      var findedIndexes = [Int]()
      
        for (index, element) in collection.enumerated() {
            if element == item {
                  findedIndexes.append(index)
            }
        }
        return findedIndexes
    }

Your code looks prettier if you enclose it with a pair of three back-tick characters (```) like this: :slight_smile:
```
Code
```

func findAll <T: Collection, U: Equatable> (_ collection: T, _ item: U) -> [Int] where T.Element == U {
  var foundIndexes = [Int]()
  
    for (index, element) in collection.enumerated () {
        if element == item {
           foundIndexes.append (index)
        }
    }
    return foundIndexes
}


1 Like

Thanx! :slight_smile:

Hi @mgmzlm,
I saw that you use enumerated method from Collection protocol.
How do you hear about this method?

Good bye!

I read Apple documentation on Collection and Sequence.

The developer documentation from Xcode or from the website?

They are same in content.

Ok :upside_down_face:

1 Like