It is possible to calculate the Levenshtein distance between two text strings using a named function such as ztiaa's LEVDIST.
But it may be more practical to use a custom function like the one you link to, or the following implementation that fuzzy matches values to a corpus using fuzzyset.js which is a JavaScript port of the Python fuzzyset.
/**
* Finds the closest matches to words using the FuzzySet library.
*
* @param {A2:A} words_to_find The text strings to find matches for.
* @param {Dictionary!W2:W} dictionary A list of words to match words_to_find against.
* @param {0.5} match_score_min Optional. A threshold value for how good the match must be. 1 means an exact match. The default is 0.33.
* @return {Array} The closest match to words_to_find found in the dictionary, or a blank value if there is no match.
* @customfunction
*/
function FindFuzzyMatch(words_to_find, dictionary, match_score_min) {
'use strict';
// version 1.2, written by --Hyde, 14 September 2022
// - hat tip to Andreas Muller
// - uses fuzzyset.js by Glen Chiacchieri, a port of fuzzyset by Mike Axiak
if (arguments.length < 2 || arguments.length > 3) {
throw `Wrong number of arguments to FindFuzzyMatch. Expected 2 or 3 arguments, but got ${arguments.length} arguments.`;
}
const words = Array.isArray(words_to_find) ? words_to_find : [[words_to_find]];
const dict = Array.isArray(dictionary) ? dictionary.flat() : [dictionary];
const fuzzyDictionary = FuzzySet(dict);
return words.map(row => row.map(word => {
if (!word) {
return null;
}
const fuzzyMatches = fuzzyDictionary.get(word, null, match_score_min);
return fuzzyMatches ? fuzzyMatches[0][1] : null; // get just the first result, ignoring its score
}));
}
// include https://github.com/Glench/fuzzyset.js/blob/master/lib/fuzzyset.js below,
// and remove the final export {} block