detect differences between two strings with Javascript

I don’t have a Javascript implementation on hand per se, but you’re doing something for which well-established algorithms exist. Specifically, I believe you’re looking for the “Levenshtein distance” between two strings — i.e. the number of insertions, substitutions and deletions (assuming you are treating a deletion as a change).

The wikipedia page for Levenshtein distance has various pseudo-code implementations from which you could start, and references which may also help you.

Leave a Comment