https://github.com/phstc/levenshtein
Levenshtein distance implemented in CoffeeScript
https://github.com/phstc/levenshtein
Last synced: about 2 months ago
JSON representation
Levenshtein distance implemented in CoffeeScript
- Host: GitHub
- URL: https://github.com/phstc/levenshtein
- Owner: phstc
- Created: 2012-04-11T19:04:01.000Z (about 14 years ago)
- Default Branch: master
- Last Pushed: 2013-03-14T12:29:23.000Z (over 13 years ago)
- Last Synced: 2025-01-27T08:45:27.305Z (over 1 year ago)
- Language: CoffeeScript
- Homepage:
- Size: 1.21 MB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Levenshtein distance implementation in CoffeeScript
It's an implementation of [Levenshtein distance](http://en.wikipedia.org/wiki/Levenshtein_distance) in [CoffeeScript](http://coffeescript.org).
## How to use it?
### To compile CoffeeScript into JavaScript
$ coffee --compile src/Levenshtein.coffee
It generates `src/Levenshtein.js`.
### To run in the browser
Firstly include the Levenshtein implementation in your code.
Then...
"pablo".levenshteinDistance("fablo"); /* should return 1 (substitution) */
### To run the test suite
$ npm test
## Examples
### examples/WordListReader.coffee
`WordListReader.coffee` finds similar words to `causes` in `samples/word.list.txt`.
$ coffee examples/WordListReader.coffee
### examples/social_network/models/friend.coffee
#### The problem
Two words are friends if they have a [Levenshtein distance](http://en.wikipedia.org/wiki/Levenshtein_distance) of 1. That is, you can add, remove, or substitute exactly one letter in word X to create word Y. A word's social network consists of all of its friends, plus all of their friends, and all of their friends' friends, and so on. Write a program to tell us how big the social network for the word "causes" is, using this word list [github.com/causes/puzzles/raw/master/word_friends/word.list](https://github.com/causes/puzzles/raw/master/word_friends/word.list).
#### To run
$ cd examples/social_network
$ npm start
## License
This code is licensed under:
MIT License GPL