Hi Guys ,
can anyway tell me why my code is not accepted
i have sorted the books in a descending order :["War and Peace", "Utopia", "Charlie and the Chocolate Factory", "A Wrinkle in Time", "A Brief History of Time"] but it was not accepted this is my code
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 |first, second|
if first > second # first book before second alphabetically
elsif first < second # first after second
else # first and second are the same


i've figured it out i simply forgot the ! after sort


The code proposed above didn't work for me. This one works just fine.
books.sort! { |firstBook, secondBook| secondBook <=> firstBook}


First, your code is way more complicated than it needs to be ... you're supposed to use the <=> operator. Second, your comments are wrong: "if first > second # first book before second alphabetically" -- if first is > second, it comes after second alphabetically; you return -1 because you want first to be sorted before second when it comes after second alphabetically.


Yeah, I have the same problem too. I try the code in the Hint, but it still does right. It says please use .sort! instead of .sort?


use this code
books.sort! do |first, second|
if first < second
elsif first > second


The following worked for me, but wasn't accepted either



Why can't we just use books.reverse!

It was accepted for me, but I suppose they want us to learn the other way for a reason?


I like Bennanni and warbs answers. This works too.

books.sort! do |first, second|
    second <=> first