@stdlib/string-base-distances-levenshtein
v0.2.2
Published
Calculates the Levenshtein (edit) distance between two strings.
Downloads
43
Readme
levenshteinDistance
Calculate the Levenshtein (edit) distance between two strings.
Installation
npm install @stdlib/string-base-distances-levenshtein
Usage
var levenshteinDistance = require( '@stdlib/string-base-distances-levenshtein' );
levenshteinDistance( s1, s2 )
Calculates the Levenshtein (edit) distance between two strings.
var dist = levenshteinDistance( 'frog', 'from' );
// returns 1
dist = levenshteinDistance( 'frog', 'froth' );
// returns 2
dist = levenshteinDistance( 'cat', 'kitty' );
// returns 4
dist = levenshteinDistance( '', 'abcdef' );
// returns 6
dist = levenshteinDistance( '1638452297', '2311638451' );
// returns 7
Examples
var levenshteinDistance = require( '@stdlib/string-base-distances-levenshtein' );
var dist = levenshteinDistance( 'algorithm', 'altruistic' );
// returns 6
dist = levenshteinDistance( 'elephant', 'hippo' );
// returns 7
dist = levenshteinDistance( 'javascript', 'typescript' );
// returns 4
dist = levenshteinDistance( 'levenshtein', 'leviathan' );
// returns 6
Notice
This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.
Community
License
See LICENSE.
Copyright
Copyright © 2016-2024. The Stdlib Authors.