Given there are several users named A, A1, A2, A3, A4,
and each user has some books.
A has books: B1, B2, B3, B4, B5
A1 has books: B2, B4
A2 has books: B3, B4, B5, B6
A3 has books: B1, B3, B5
A4 has books: B1, B6
The ruby/rails objects relations is:
+ User.class
+ Book.class
A user has many books, and a book belongs to a user, so we have user.books, and book.user.
Question
The question is how to use Ruby to sort the users (A1,A2,A3,A4)
by which has the most books in common with user A.
Result
The result should be [A2, A3, A1, A4]
or something like that.
Hope you guys can help me to implements this algorithm with Ruby/ Rails.