code: function edit_distance(a, b) {
    // create a 2 dimensions array
    const m = a.length;
    const n = b.length;
    const dp = new Array(m + 1);
    for (let i = 0; i <= m; i++) {
      dp[i] = new Array(n + 1);
    }
  
    // init dp array
    for (let i = 0; i <= m; i++) {
      dp[i][0] = i;
    }
    for (let j = 0; j <= n; j++) {
      dp[0][j] = j;
    }
  
    // dynamic approach
    for (let i = 1; i <= m; i++) {
      for (let j = 1; j <= n; j++) {
        if (a[i - 1] !== b[j - 1]) {
          dp[i][j] = triple_min(
            1 + dp[i - 1][j], // deletion
            1 + dp[i][j - 1], // insertion
            1 + dp[i - 1][j - 1], // replacement
          );
        } else {
          dp[i][j] = dp[i - 1][j - 1];
        }
      }
    }
    return dp[m][n];
  }
docs: Damerau–Levenshtein distance  implemention ref: https://en.wikipedia.org/wiki/Damerau%E2%80%93Levenshtein_distance