What's Happening When I use Two Indexes On .each Method?

books = ["Charlie and the Chocolate Factory", "War and Peace", "Utopia", "A Brief History of Time", "A Wrinkle in Time"] # To sort our books in ascending order, in-place books.sort! { |firstBook, secondBook| firstBook <=> secondBook } # Sort your books in descending order, in-place below books.sort! do |firstBook, secondBook| secondBook <=> firstBook end

Am I understanding correctly that by using |firstBook, secondBook| Ruby is creating two lists because it is iterating through the array items twice?

War and Peace, War and Peace
Utopia, Utopia

and then comparing somehow? (I guess with what it determines to be the best method)

You must select a tag to post in this category. Please find the tag relating to the section of the course you are on E.g. loops, learn-compatibility

When you ask a question, don’t forget to include a link to the exercise or project you’re dealing with!

If you want to have the best chances of getting a useful answer quickly, make sure you follow our guidelines about how to ask a good question. That way you’ll be helping everyone – helping people to answer your question and helping others who are stuck to find the question and answer! :slight_smile:

Not two lists, just two variables for comparison. This is how we are able to order the sort either ascending or descending.