FAQ: Methods, Blocks, & Sorting - Sorting

Hi p0nd3r,

I believe, rereading the instructions/explanation on the “Foundations” exercise (13/19) and “The Combined Comparison Operator” (14/19), the answer to your question about 2 values compared in an array of more than 2 values has to do with how the algorithms work. From my understanding, I believe the .sort! method is comparing each of the values in the array to each of the others. So for each comparison that it runs, there are two values being compared. The algorithm doesn’t compare all 5 values at once, but two at a time.

So for each of those comparison that it runs, we’re telling it how to compare those two items. In order to do this, we are calling the two values being compared at each given step fruit1 and fruit2.

Crazy that they dropped “Try it with an if/else statement!” in there without any guidance or an example of the correct answer. That’s what I came to the forums to find. Thanks for posting yours.

1 Like