Skip to content

Commit e221e60

Browse files
committed
Replace another nested conditional with gaurd clause
1 parent 5a6d75c commit e221e60

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

JavaScript/chapter01/1.5 - OneAway/rroque98_sol.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,16 @@ const isOneAway = (str1, str2) => {
2222
return true;
2323
}
2424
const longStr = str1.length > str2.length ? str1 : str2;
25-
const shortStr = str1.length < str2.length ? str1 : str2;
25+
const shortStr = str1.length <= str2.length ? str1 : str2;
2626
for (let i = 0, x = 0; i < longStr.length && x < shortStr.length; i++, x++) {
27-
if (longStr[i] !== shortStr[x]) {
28-
errorCount++;
29-
if (errorCount > 1) {
30-
return false;
31-
}
32-
i++;
27+
if (longStr[i] === shortStr[x]) {
28+
continue;
29+
}
30+
errorCount++;
31+
if (errorCount > 1) {
32+
return false;
3333
}
34+
i++;
3435
}
3536
return true;
3637
};

0 commit comments

Comments
 (0)