I needed a very basic spell correction string matcher in my current NodeJS project so I wrote a simple class called
that compares a string against another string and matches if it's 1 edit distance away. With it you can do things like Google search's "Did you mean: poop?" when you search for pop.
Note, this code doesn't check popularity of correct words (e.g. "pop" might appear much more often than "poop" so it'll suggest "pop" if you enter "poup"). Anyway this simple snippet from the unit tests will reveal how it works:
The most basic use case is if you have a quiz and you want to accept some spelling mistakes. "What's the capital of Sweden?; STOKHOLM; Correct!"
For the unlazy this NodeJS code can very easily be used in a browser by simply removing the
Note! I wrote this in an airport lounge so I'm sure it can be improved lots more.