In the "solution" branch, the "total" variable is calculated incorrectly here:
|
var total = agreements + symmetricDifference(user1.likes, user2.likes).length + symmetricDifference(user1.dislikes, user2.dislikes).length |
and here:
|
var total = disagreements + symmetricDifference(user1.likes, user2.dislikes).length + symmetricDifference(user1.dislikes, user2.likes).length |
var total = agreements + symmetricDifference(user1.likes, user2.likes).length + symmetricDifference(user1.dislikes, user2.dislikes).length
...will double-count certain movies in the case where one user likes some of the movies that the other user dislikes.
The same applies for...
var total = disagreements + symmetricDifference(user1.likes, user2.dislikes).length + symmetricDifference(user1.dislikes, user2.likes).length
...when one user likes some of the same movies as the other user.
This causes the final value to be returned by both functions and fed into calculateSimilarity to be incorrect.