Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

create a function (in javascript) that will take those two strings and transpose

ID: 3817845 • Letter: C

Question

create a function (in javascript) that will take those two strings and transpose them, so that the strings go from top to bottom instead of left to right. Having some problems getting my code to work correctly, the spacing is not correct when it runs. There should be one space in between the two characters. If one string is longer than the other, there should be a space where the character would be

function transposeTwoStrings(arr) {
var result = '';
var count = 0;
while(arr[0][count] || arr[1][count]) {
result += arr[0][count] || ' ';
result += ' ';
result += arr[1][count] || ' ';
result += ' ' ;
count++;
}
return result;

}

console.log(transposeTwoStrings(['a', 'cat']));

Explanation / Answer

Below is the edited code:-

Thank you.