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.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.