Generic edit distance algorithm for Javascript