Skip to content

Instantly share code, notes, and snippets.

@kfarst
Last active June 6, 2017 19:36
Show Gist options
  • Save kfarst/b87afa5841babd07d08d6b6f1b05aff0 to your computer and use it in GitHub Desktop.
Save kfarst/b87afa5841babd07d08d6b6f1b05aff0 to your computer and use it in GitHub Desktop.
function transposeTwoStrings (string1, string2) {
var i = 0
// Continue checking each letter of each string as long as at least one of the strings still has letters
while (string1[i] !== undefined || string2[i] !== undefined) {
var letterColumn = '';
// As long as the index we're at still has a letter, append it to the string, otherwise append an empty space
if (string1[i] !== undefined) {
letterColumn = letterColumn.concat(string1[i]);
} else {
letterColumn = letterColumn.concat(' ');
}
// Space between the two letter columns
letterColumn = letterColumn.concat(' ');
// Same as above with string1
if (string2[i] !== undefined) {
letterColumn = letterColumn.concat(string2[i]);
} else {
letterColumn = letterColumn.concat(' ');
}
// Increment the index
i++;
// Print each letter column to the console
console.log(letterColumn);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment