Skip to content

Instantly share code, notes, and snippets.

@PetarIvancevic
Created October 27, 2017 18:52
Show Gist options
  • Save PetarIvancevic/a367497d7e702a9013a552e2976ec56a to your computer and use it in GitHub Desktop.
Save PetarIvancevic/a367497d7e702a9013a552e2976ec56a to your computer and use it in GitHub Desktop.
Euclidean distance formula
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