Levenshtein Distance and Luhn Validation in PowerShell
Recently i needed a rudimentary algorithm that could give me the edit distance between two strings. Usually, when i do this type of thing i throw together a quick script that gets thrown away once i am done with it. This time, i decided to turn this into a side project, the product of which is hosted on Github. The algorithms module is the latest in my collection of PowerShell modules and has launched with support for both Levenshtein Distance and Luhn Validation. The idea is that every time i need some sort of algorithm in PowerShell i will just add it to the module. The module itself is published to the PowerShell module gallery, so you can be up and running in just a few lines of code.
The idea behind he Levenshtein Distance is that we count the number of insert, substitute and delete operations that it takes to turn the source string into the target string. This could be useful, for example, when choosing which words to show in a suggestion list. It is also very useful for doing something like rudimentary spell checking. The function is really easy to use requiring only two parameters, the source string and the target string.
On the other hand, Luhn validation is a simple checksum formula. It is used to validate credit card numbers and IMEI numbers for example. The function only takes a single parameter and returns a boolean value. The Luhn algorithm is also known as the "modulus 10" or "mod 10" algorithm.
Perhaps the best news is that the library is built on top of a PowerShell CI pipeline, complete with Pester tests. To be honest, there is not many tests at the moment but plan to add them as i find bugs or edge caases.
So thats about all i have for you this time round. Dont forget to star the project on Github and leave a comment if you have any questions. In the next post, we will look at how to create to create a PowerShell CI pipeline using Gitlab and and Microsoft Azure.