Hi – I on Chapter 24 of the 2nd Edition which is about Collection Classes. I’m really struggling with the 1st challenge.
The challenge is to add a method to the BNRPortfolio class that returns an NSArray of only the top three most valuable holdings, sorted by current value in dollars.
Q1 – In the employee example, all the sorting was handled in main. Maybe that is throwing me off. The array to be sorted is in the BNRPortfolio Class, but the value to sort on is not a property, it is a result returned by a method of the object held in the array. I’m not really sure where to start. Any assistance would be appreciated.
Q2 – Looking ahead to the second part of the question, is there an elegant way to handle getting the “top 3 values” only? Once the mutable array is sorted, do I just take the first three objects by the index? I can’t think that a predicate & filtering would work for getting the top x values. Again, any assistance would be appreciated!