(string)
| 133 | // console.log('cat'.slice(1));// at |
| 134 | |
| 135 | function reverseString(string) { |
| 136 | |
| 137 | if(string.length === 1) return string; |
| 138 | |
| 139 | let firstLetter = string[0]; |
| 140 | console.log('up call stack',firstLetter, string); |
| 141 | |
| 142 | let res = reverseString(string.slice(1)) + firstLetter; |
| 143 | |
| 144 | console.log('down the stack',res) |
| 145 | return res; |
| 146 | }; |
| 147 | |
| 148 | |
| 149 | console.log(reverseString('cat'));// 'tac' |