about summary refs log tree commit diff
path: root/users/wpcarro/scratch/deepmind/part_two/reverse-string-in-place.ts
diff options
context:
space:
mode:
Diffstat (limited to 'users/wpcarro/scratch/deepmind/part_two/reverse-string-in-place.ts')
-rw-r--r--users/wpcarro/scratch/deepmind/part_two/reverse-string-in-place.ts13
1 files changed, 13 insertions, 0 deletions
diff --git a/users/wpcarro/scratch/deepmind/part_two/reverse-string-in-place.ts b/users/wpcarro/scratch/deepmind/part_two/reverse-string-in-place.ts
new file mode 100644
index 000000000000..d714dfef997f
--- /dev/null
+++ b/users/wpcarro/scratch/deepmind/part_two/reverse-string-in-place.ts
@@ -0,0 +1,13 @@
+// Reverse array of characters, `xs`, mutatively.
+function reverse(xs: Array<string>) {
+  let i: number = 0;
+  let j: number = xs.length - 1;
+
+  while (i < j) {
+    let tmp = xs[i];
+    xs[i] = xs[j]
+    xs[j] = tmp
+    i += 1
+    j -= 1
+  }
+}