Skip to content

Instantly share code, notes, and snippets.

@Muon
Muon / levenshtein.coffee
Created February 15, 2012 17:27
Levenshtein algorithm implementation in CoffeeScript
levenshtein = (a, b) ->
# Handle degenerate cases
if a == b
return 0
unless a.length > 0 and b.length > 0
return a.length or b.length
# Normalize order for cache
if b.length < a.length