09/15 getting technical


#1

hey, Samuel here.

we need to sort the following array in a descending manner.

here's my code:

books = ["Charlie and the Chocolate Factory", "War and Peace", "Utopia", "A Brief History of Time", "A Wrinkle in Time"]

sorted = books.sort!
sorted.reverse

the editor returns the sorted book in a descending manner but I can't go on to the next level.
I think they want me to do it another way ... here's the code they give us to help us:

books = ["Charlie and the Chocolate Factory", "War and Peace", "Utopia", "A Brief History of Time", "A Wrinkle in Time"]
books.sort! { |firstBook, secondBook| firstBook <=> secondBook }


#2

The editor edits text. It does not return anything, doesn't run any code, doesn't print anything. Printing and returning are very different things.

Did you write code that prints to the console?
If not, then how was what you see printed, and what was printed? Without that knowledge, make no assumptions about what it is you're seeing.

Print out the content of the array yourself.

As for how to do it, I assume the instructions offer some idea about that?


#3

hey ionatan,
thank you for your reply, I got the solution after sleeping on it.
Sam


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.