Here is my ruby code:
books = ["Charlie and the Chocolate Factory", "War and Peace", "Utopia", "A Brief History of Time", "A Wrinkle in Time"]
books.sort! {
|firstBook, secondBook|
boolean_value = firstBook <=> secondBook
print "first book is = '#{firstBook}'"
print " , second book is = '#{secondBook}'"
puts " and there compare result is #{boolean_value}"
}
Questions:
- This code runs single iteration and then it gives error
in 'sort!': comparison of String with String failed (ArgumentError)
- When firstbook = "Charlie and the Chocolate Factory" then secondBook should be "War and Peace" but it code chooses "Utopia" to compare. Why?