I’m just going to leave this nifty little PHP snippet here, and recommend against it’s use. It could very well be shorter and more concise, probably a bit more performant too, but it works:
View the code on Gist.
It also encourages bad practices and ambiguity ( should elngth be mapped on to length1 or length2? If you’re willing to run levenshtein in your head, maybe you should spell correctly ).
Inspired by this tweet:
>>> def method_missing(n, *a, &b); send(methods.min_by { |m| levenshtein(n.to_s, m.to_s) }, *a, &b); end
>> p [1, 2, 3].elngth
3It's fine.
— Gary Bernhardt (@garybernhardt) October 10, 2012
Leave a Reply