about summary refs log tree commit diff
path: root/deepmind/part_two/reverse-string-in-place.ts
diff options
context:
space:
mode:
Diffstat (limited to 'deepmind/part_two/reverse-string-in-place.ts')
-rw-r--r--deepmind/part_two/reverse-string-in-place.ts17
1 files changed, 12 insertions, 5 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
+  }
+}