Git Product home page Git Product logo

js-levenshtein's Introduction

js-levenshtein Build Status

The most efficient JS implementation calculating the Levenshtein distance, i.e. the difference between two strings.

Based on Wagner-Fischer dynamic programming algorithm, optimized for speed and memory

  • use a single distance vector instead of a matrix
  • loop unrolling on the outer loop
  • remove common prefixes/postfixes from the calculation
  • minimize the number of comparisons

Install

$ npm install --save js-levenshtein

Usage

const levenshtein = require('js-levenshtein');

levenshtein('kitten', 'sitting');
//=> 3

Benchmark

$ npm run bench
  
                      50 paragraphs, length max=500 min=240 avr=372.5
             126 op/s » js-levenshtein
              81 op/s » talisman
              74 op/s » levenshtein-edit-distance
              73 op/s » leven
              34 op/s » fast-levenshtein

                      100 sentences, length max=170 min=6 avr=57.5
           2,441 op/s » js-levenshtein
           1,615 op/s » talisman
           1,365 op/s » levenshtein-edit-distance
           1,342 op/s » leven
             687 op/s » fast-levenshtein

                      2000 words, length max=20 min=3 avr=9.5
           2,607 op/s » js-levenshtein
           1,783 op/s » talisman
           1,830 op/s » levenshtein-edit-distance
           1,608 op/s » leven
           1,119 op/s » fast-levenshtein

Benchmarks was performed with node v8.6.0 on a MacBook pro 15", 2.9 GHz Intel Core i7

License

MIT © Gustaf Andersson

js-levenshtein's People

Contributors

gustf avatar mvasilkov avatar

Stargazers

NOOB2868 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.