Method String.levenshtein
Calculate the Levensthein distance (LD) of two strings
-
Syntax
Number String.levenshtein(String t )
Compute the Levenshtein distance (LD) between the source string and the target stringt. The LD is the number of changes to the source string we have to make to get the target string. Changes are defined as a letter changed, inserted or deleted. -
Parameters
String t- The target string
- Return value The LD of the two strings.
-
Examples
- To find the LD of source string 'GUMBO' and the target string 'GAMBOL'.
// Define source string var s = 'GUMBO'; // Define target string var t = 'GAMBOL'; // Output is 2 (One character differs and one is missing) s.levensthein(t);
- Resources The LD algorithm is credited to Michael Gilleland and is considered public domain. See http://www.merriampark.com/ld.htm for more information.
-
Download
Source
Unless otherwise noted all code in the JSLab Standard Library is licensed as GPLv3. See http://www.gnu.org/licenses/gpl.html for the entire license.
