Skip to content

Commit 2feba68

Browse files
committed
Remove unnecessary variable declaration in for loop
1 parent e221e60 commit 2feba68

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

JavaScript/chapter01/1.5 - OneAway/rroque98_sol.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,14 @@ const isOneAway = (str1, str2) => {
2323
}
2424
const longStr = str1.length > str2.length ? str1 : str2;
2525
const shortStr = str1.length <= str2.length ? str1 : str2;
26-
for (let i = 0, x = 0; i < longStr.length && x < shortStr.length; i++, x++) {
27-
if (longStr[i] === shortStr[x]) {
26+
for (let i = 0; i + errorCount < longStr.length; i++) {
27+
if (longStr[i + errorCount] === shortStr[i]) {
2828
continue;
2929
}
3030
errorCount++;
3131
if (errorCount > 1) {
3232
return false;
3333
}
34-
i++;
3534
}
3635
return true;
3736
};

0 commit comments

Comments
 (0)