create a function (in javascript) that will take those two strings and transpose
ID: 3814709 • 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. There should be one spacein between the 2 characters, and if one string is longer than other, there should be space where the character would be. Having some problems getting my code to work correctly, here's what I have so far:
function transposeTwoStrings(arr){
var arrayOne = [];
for(var i = 0; i < arr.length; i++) {
arrayOne.push([]);
};
for(var i = 0; i < arr.length; i++){
for(var j = 0; j < arr.length; j++) {
arrayOne[j].push(array[i][j]);
};
};
return(arayOne);
}
transposeTwoStrings(['hello', 'world']);
Explanation / Answer
/* You will be given an array that contains two strings. Your job is to create a function that will take those two strings and transpose them, so that the strings go from top to bottom instead of left to right. e.g. transposeTwoStrings(['Hello','World']); should return: H W e o l r l l o d */ function transposeTwoStrings(arr) { var size = 0; if(arr[0].length > arr[1].length) size = arr[0].length else size = arr[1].length result = []; for (var i = 0; iRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.