Complete InterviewCake reverse-string-in-place

Wrote a function in TypeScript to reverse an array of characters mutatively.
This commit is contained in:
William Carroll 2020-02-12 15:53:21 +00:00
parent e1427dd8b1
commit 5ec5a6da8c
2 changed files with 13 additions and 6 deletions

View file

@ -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
}
}

View file

@ -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