Search code examples
javascripttextsimilarity

Algorithm to compute similarity of two strings in javascript


Is there any text similarity algorithm in javascript? I want to compare too essays to determine how similar they are. I was thinking about edit distance, but I don't know how to translate it into percentage.


Solution

  • Take a look at jsdifflib, a javascript implementation of python's SequenceMatcher. You can get the similar percentage: difflib.ratio(string1, string2) * 100. Here is the demo. Hope this is what you want.