Skip to content

Commit bd4deb0

Browse files
committed
suggestionList: improve readability
1 parent 02cd678 commit bd4deb0

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/jsutils/suggestionList.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,18 @@ class LexicalDistance {
8080
for (let j = 1; j <= bLength; j++) {
8181
const cost = a[i - 1] === b[j - 1] ? 0 : 1;
8282

83-
d[i][j] = Math.min(
84-
d[i - 1][j] + 1,
85-
d[i][j - 1] + 1,
86-
d[i - 1][j - 1] + cost,
83+
let currentCell = Math.min(
84+
d[i - 1][j] + 1, // delete
85+
d[i][j - 1] + 1, // insert
86+
d[i - 1][j - 1] + cost, // substitute
8787
);
8888

8989
if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1]) {
90-
d[i][j] = Math.min(d[i][j], d[i - 2][j - 2] + 1);
90+
// transposition
91+
currentCell = Math.min(currentCell, d[i - 2][j - 2] + 1);
9192
}
93+
94+
d[i][j] = currentCell;
9295
}
9396
}
9497

0 commit comments

Comments
 (0)