levenshteinDistance method

Future<int> levenshteinDistance(
  1. String other
)

Computes the minimum number of single-character edits (insertions, deletions or substitutions) required to change the current String into the other

Implementation

Future<int> levenshteinDistance(String other) async {
  if (isEmpty) return other.length;
  if (other.isEmpty) return length;
  if (this[0] == other[0]) return tail.levenshteinDistance(other.tail);
  return 1 +
      (await Future.wait(<Future<int>>[
        levenshteinDistance(other.tail),
        tail.levenshteinDistance(other),
        tail.levenshteinDistance(other.tail),
      ]))
          .reduce(min);
}