export function one(a: string, b: string, i: number, j: number) {
    if (a[i] === b[j]) {
        return 0;
    }

    return 1;
}

// Computes the difference between the strings a and b.
// @a, b: The strings to compare
// @i, j: From where to compare (a_i and b_j)
// @ret : The distance in insertions, deletions and changes
export function lev(a: string, b: string, i: number, j: number) {
    if (Math.min(i, j) === 0) {
        return Math.max(i, j);
    } else {
        return Math.min(
            lev(a, b, i - 1, j) + 1,
            lev(a, b, i, j - 1) + 1,
            lev(a, b, i - 1, j - 1) + one(a, b, i, j)
        );
    }
};

// Computes the difference between the strings a and b.
// @a, b: The strings to compare
// @ret : The distance in insertions, deletions and changes
export function levW(a: string, b: string) {
    return lev(a, b, a.length, b.length);
}
