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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!