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
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']));
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
