Created
October 27, 2017 18:52
-
-
Save PetarIvancevic/a367497d7e702a9013a552e2976ec56a to your computer and use it in GitHub Desktop.
Euclidean distance formula
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function euclideanDistance (user1, user2) { | |
const n = _.size(user1.reviews) | |
let coefficient = 0 | |
if (n === 0) { | |
return n | |
} | |
for (let i = 0; i < n; i++) { | |
coefficient += Math.pow(user1.reviews[i].rating - user2.reviews[i].rating, 2) | |
} | |
return 1 / (1 + Math.sqrt(coefficient)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment