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.
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.
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."
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.