1
Custom Edit Distance2 with customizable costs.
The usual algorithmInstall
npm install custom-edit-distance
Calculate
const defaultCalculator = ;defaultCalculatorshould;
Customize Costs
const LEVENSHTEIN = { return 0; } { return 1; } { return 1; } { return 1; };const defaultCalculator = LEVENSHTEIN;
For convenience, we default to the Levenshtein3 distance costs. We also export it as LEVENSHTEIN.
Customize Equivalence
const equivalence = { a == b; // Only check for abstract equivalence}; const defaultCalculator = null equivalence;
For convenience we default to strict equality (===).
Sequences don't have to be Strings
const defaultCalculator = ;defaultCalculatorshould;
This is where defining cost can shine:
const valueDistanceCalculator = { return insertedValue; } { return removedValue; } { return Math; };valueDistanceCalculatorshould;
Get the cost matrix
const defaultCalculator = ;const costMatrix = defaultCalculatorshould;
From this you could determine the edit path, or inspect the cost of other edit paths.