Need guidance on Gold Challenge

The topic on Generics is quite tough for me.
I am tackling the gold challenge but so far no luck yet.

The hint is quite confusing to me “You will need to change the return type from [Int] to an array of an associated type of the Collection protocol”. Can anyone explain on this?
I don’t know what to do with Set as it does not have a defined ordering. How to get the location of a item in a set?

Any guidance on this challenge is much appreciated.

Same thing here. The wording is confusing.

First of all, will that be a standalone function, or a type method? Like, do we create it inside the Stack we created in the chapter? Or is this a completely new file? None of the chapter examples involved creating a standalone Generic function, and considering the level of vagueness this concept offers, it is really hard to understand how to go about this.

Any help is appreciated.

Reading the Generics section in The Swift Programming Language document will make it easier to understand the concept of generics.

Here is an excerpt from that section:


Generic code enables you to write flexible, reusable functions and types that can work with any type, subject to requirements that you define. You can write code that avoids duplication and expresses its intent in a clear, abstracted manner."

Give it a try and see how you feel afterwards.

Tank you very much for you advice! I will do that. The concept of Generics is easy to understand, but I found it hard to apply. Reading a different resource will probably help.