Skip to content

similarity

Calculate the similarity between two strings using the Levenshtein distance algorithm. One thing to note is that the argument order is unimportant. The algorithm will always return the same result regardless of the order of the arguments. Adapted from [@fabiospampinato/tiny-levenshtein](https://github.com/fabiospampinato/tiny-levenshtein) with ❤️.

Usage

similarity("abc", "abc"); // 0
similarity("a", "b"); // 1
similarity("ab", "ac"); // 1
similarity("ac", "bc"); // 1
similarity("abc", "axc"); // 1
similarity("kitten", "sitting"); // 3

Installation

Terminal window
npx atmx add helper similarity