Alternative string concatenation of a two string in Javascript

function GetString(string1,string2) {
var str1 = string1.split('');
var str2 = string2.split('');

var finalString = "";
var length = str1.length > str2.length ? str2.length : str1.length;
for (var i = 0; i str2.length) {
var difference = str1.length - str2.length;
for (var i = 0; i < difference; i++) {
var rem = str1[str2.length + i];
finalString = finalString + rem;
}

} else {
var difference = str2.length - str1.length;
for (var i = 0; i < difference; i++) {
var rem = str2[str1.length + i];
finalString = finalString + rem;
}
}
return finalString;
}

var result= GetString(“INDIA”, “USA”);
Output : IUNSDAIA

One thought on “Alternative string concatenation of a two string in Javascript

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s