Skip to content

Instantly share code, notes, and snippets.

@jmarmolejos
Created May 29, 2017 18:17
Show Gist options
  • Save jmarmolejos/ad57881fdd273ce0aa45b82524162294 to your computer and use it in GitHub Desktop.
Save jmarmolejos/ad57881fdd273ce0aa45b82524162294 to your computer and use it in GitHub Desktop.
function findJaccardIndex(collection1, collection2) {
return _.intersection(collection1, collection2).length / _.union(collection1, collection2).length
}
console.log(findJaccardIndex("Foo".split(''), 'Bar'.split(''))); // 0
console.log(findJaccardIndex("Foo".split(''), 'Far'.split(''))); // 0.2
console.log(findJaccardIndex("Foo".split(''), 'For'.split(''))); // 0.66
console.log(findJaccardIndex("Foo".split(''), 'Foo'.split(''))); // 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment