File tree Expand file tree Collapse file tree 1 file changed +10
-14
lines changed
JavaScript/chapter01/1.5 - OneAway Expand file tree Collapse file tree 1 file changed +10
-14
lines changed Original file line number Diff line number Diff line change @@ -19,21 +19,17 @@ const isOneAway = (str1, str2) => {
19
19
}
20
20
}
21
21
}
22
- } else {
23
- const longStr = str1 . length > str2 . length ? str1 : str2 ;
24
- const shortStr = str1 . length < str2 . length ? str1 : str2 ;
25
- for (
26
- let i = 0 , x = 0 ;
27
- i < longStr . length && x < shortStr . length ;
28
- i ++ , x ++
29
- ) {
30
- if ( longStr [ i ] !== shortStr [ x ] ) {
31
- errorCount ++ ;
32
- if ( errorCount > 1 ) {
33
- return false ;
34
- }
35
- i ++ ;
22
+ return true ;
23
+ }
24
+ const longStr = str1 . length > str2 . length ? str1 : str2 ;
25
+ 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 ;
36
31
}
32
+ i ++ ;
37
33
}
38
34
}
39
35
return true ;
You can’t perform that action at this time.
0 commit comments