моя грязная реализация,: p
var nl_first = "a,b,c,d,e";
var nl_second = "1,2,3";
console.log(customJoin(nl_first, nl_second));
//a,1,b,2,c,3,d,e
var nl_first = "a,b,c,d,e";
var nl_second = "1,2,3,4,5";
console.log(customJoin(nl_first, nl_second));
//a,1,b,2,c,3,d,4,e,5
var nl_first = "a,b,c,d,e";
var nl_second = "1,2,3,4,5,6";
console.log(customJoin(nl_first, nl_second));
//a,1,b,2,c,3,d,4,e,5,6
function customJoin(first, second) {
if (first.length > second.length) {
var secondArray = second.split(',');
secondArray.reverse();
var result = first.replace(/,/g, function (text) {
var item = secondArray.pop();
return (item) ? text + item + text: text;
});
return result;
} else {
var firstArray = first.split(',');
firstArray.reverse();
second = ',' + second;
var result = second.replace(/,/g, function (text) {
var item = firstArray.pop();
return (item) ? text + item + text: text;
});
result = result.replace(/^,/, '');
return result;
}
}