about summary refs log tree commit diff
path: root/scratch/deepmind/part_two/reverse-string-in-place.ts
blob: d714dfef997f52bf530f9788cce16f30d0376fa6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
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
  }
}