Skip to content

Commit ca42d35

Browse files
Completed reverse string challenge (CoffeelessProgrammer#2 IP)
1 parent ef23af8 commit ca42d35

File tree

5 files changed

+32
-2
lines changed

5 files changed

+32
-2
lines changed

Data-Structures/Arrays/My_Array_Implementation.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class MyArray<T> {
8282
}
8383

8484

85+
8586
let helloArray = new MyArray<string>();
8687

8788
helloArray.push('Hello'); // O(1)

Playground/Compare_Arrays.test.ts renamed to Playground/Interview-Prep/Compare_Arrays.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { assertEquals, assertNotEquals } from "../test_deps.ts";
1+
import { assertEquals, assertNotEquals } from "../../test_deps.ts";
22

33
import { containsCommonItem } from "./Compare_Arrays.ts";
44

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Challenge: Reverse the characters of a string, preserving
2+
// capitalization and spaces
3+
//
4+
// Example:
5+
// Input — "Avatar the Last Airbender"
6+
// Output — "rednebriA tsaL eht ratavA"
7+
8+
function reverseString(input: string): string {
9+
let reversed: string[] = [];
10+
11+
if (input.length > 1) {
12+
for (let i = input.length; i > 0; --i) {
13+
reversed.push(input.charAt(i-1)); // input[i-1] will also work in JS
14+
}
15+
}
16+
17+
return reversed.join('');
18+
}
19+
20+
function reverseWithJavascriptVoodoo(input: string): string {
21+
return input.split('').reverse().join('');
22+
}
23+
24+
const reverseWithMoreVoodoo = (str: string) => [...str].reverse().join('');
25+
26+
27+
28+
console.log(reverseString("ATLA"));
29+
console.log(reverseString("Avatar the Last Airbender"));

Playground/Sum_Pair.ts renamed to Playground/Interview-Prep/Sum_Pair.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Problem: Given an array of unordered numbers and a sum,
1+
// Challenge: Given an array of unordered numbers and a sum,
22
// is there a pair of numbers which add up to the sum?
33

44

0 commit comments

Comments
 (0)