MCPcopy Create free account
hub / github.com/appacademy/Module-1-Resources / reverseString

Function reverseString

w3/d2/recursion.js:135–146  ·  view source on GitHub ↗
(string)

Source from the content-addressed store, hash-verified

133// console.log('cat'.slice(1));// at
134
135function 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
149console.log(reverseString('cat'));// 'tac'

Callers 1

recursion.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected