File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed
chapter01/1.9 - String Rotation Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change 1+ // var stringRotation = function(string1, string2) {
2+ // let counter = 0
3+ // let currStr = string1
4+
5+ // while (counter !== string1.length) {
6+ // // rotate string
7+ // // compare to string 2
8+ // // can only iterate the numer of times characters in string
9+ // currStr = currStr.slice(1) + currStr[0]
10+ // console.log(currStr, string2)
11+ // if (currStr === string2) return true
12+ // counter++
13+ // }
14+
15+ // return false
16+ // };
17+
118var stringRotation = function ( string1 , string2 ) {
19+ let counter = 0
20+ let currStr = string1
21+
22+ while ( counter !== string1 . length ) {
23+ // rotate string
24+ // compare to string 2
25+ // can only iterate the numer of times characters in string
26+ currStr = currStr . slice ( 1 ) + currStr [ 0 ]
27+ console . log ( currStr , string2 )
28+ if ( currStr === string2 ) return true
29+ counter ++
30+ }
231
32+ return false
333} ;
434
535// Approaches:
You can’t perform that action at this time.
0 commit comments