Skip to content

Commit ef795eb

Browse files
Completed reverse string w/ recursion (Closes CoffeelessProgrammer#9)
1 parent 30230dc commit ef795eb

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
function reverseStringRecursive(str: string): string {
2+
if (str.length===0) return "";
3+
4+
return reverseStringRecursive(str.substring(1)) + str.charAt(0);
5+
}
6+
7+
function printReverseString(str: string) {
8+
console.log(str, '–>', reverseStringRecursive(str));
9+
}
10+
11+
12+
//---------------------------------------------------------------------
13+
// ---------- MAIN PROGRAM ----------
14+
//---------------------------------------------------------------------
15+
if (import.meta.main) {
16+
17+
printReverseString("Hello World!");
18+
printReverseString("C0mp!ex1tY");
19+
printReverseString("Avatar: The Last Airbender");
20+
21+
// RUN: deno run Playground/Challenges/Recursion/ReverseString.ts
22+
}

Playground/Demos/Classes_101.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: deno run Playground/Classes_Demo.ts
1+
// RUN: deno run Playground/Demos/Classes_101.ts
22

33
class Bender {
44
protected name: string;

Playground/Demos/Objects_101.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// RUN: deno run Playground/Demos/Objects_101.ts
12

23
console.log('------------------------- Episode 1 -------------------------');
34
const episode1 = {

0 commit comments

Comments
 (0)