about summary refs log tree commit diff
diff options
context:
space:
mode:
-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