Skip to content

Commit 4005f01

Browse files
authored
Update reverse_string_with_recursion.js
1 parent 1fd582b commit 4005f01

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

algorithms/reverse_string_with_recursion.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ function reverseString(str){
99

1010
if (str.length <= 1) return str;
1111

12-
return str.slice(str.length - 1, str.length) + reverseString(str.slice(0, str.length - 1));
12+
const lastChar = str.slice(str.length - 1, str.length);
13+
const remainingStr = str.slice(0, str.length - 1)
14+
15+
return lastChar + reverseString(remainingStr);
1316

1417
}
1518

0 commit comments

Comments
 (0)