about summary refs log tree commit diff
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2020-02-12T15·53+0000
committerWilliam Carroll <wpcarro@gmail.com>2020-02-12T15·53+0000
commit5ec5a6da8cbfe3c35558fd2c17ef779b5d0ccb54 (patch)
tree88729728b670eb90d4b3f4dfc2c242c5a1d77b0b
parente1427dd8b1ec59f46d16d1c6591364d83e75b39e (diff)
Complete InterviewCake reverse-string-in-place
Wrote a function in TypeScript to reverse an array of characters mutatively.
-rw-r--r--deepmind/part_two/reverse-string-in-place.ts17
-rw-r--r--deepmind/part_two/todo.org2
2 files changed, 13 insertions, 6 deletions
diff --git a/deepmind/part_two/reverse-string-in-place.ts b/deepmind/part_two/reverse-string-in-place.ts
index 628b95a6bf91..d714dfef997f 100644
--- a/deepmind/part_two/reverse-string-in-place.ts
+++ b/deepmind/part_two/reverse-string-in-place.ts
@@ -1,6 +1,13 @@
-function main(x: number) {
-  console.log(x + 1);
-  console.log("Hello, world.");
-}
+// Reverse array of characters, `xs`, mutatively.
+function reverse(xs: Array<string>) {
+  let i: number = 0;
+  let j: number = xs.length - 1;
 
-main(10);
+  while (i < j) {
+    let tmp = xs[i];
+    xs[i] = xs[j]
+    xs[j] = tmp
+    i += 1
+    j -= 1
+  }
+}
diff --git a/deepmind/part_two/todo.org b/deepmind/part_two/todo.org
index 9a163e01672b..510073e6e2cd 100644
--- a/deepmind/part_two/todo.org
+++ b/deepmind/part_two/todo.org
@@ -1,6 +1,6 @@
 * Array and string manipulation
 ** TODO Merging Meeting Times
-** TODO Reverse String in Place
+** DONE Reverse String in Place
 ** TODO Reverse Words
 ** TODO Merge Sorted Arrays
 ** TODO Cafe Order Checker