We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 5a6d75c commit e221e60Copy full SHA for e221e60
JavaScript/chapter01/1.5 - OneAway/rroque98_sol.js
@@ -22,15 +22,16 @@ const isOneAway = (str1, str2) => {
22
return true;
23
}
24
const longStr = str1.length > str2.length ? str1 : str2;
25
- const shortStr = str1.length < str2.length ? str1 : str2;
+ 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]) {
28
- errorCount++;
29
- if (errorCount > 1) {
30
- return false;
31
- }
32
- i++;
+ if (longStr[i] === shortStr[x]) {
+ continue;
+ }
+ errorCount++;
+ if (errorCount > 1) {
+ return false;
33
34
+ i++;
35
36
37
};
0 commit comments