自己的解法:
2x2 种情况判断
function solution(urlStr) {
const pre = urlStr.split(",")[0];
const after = urlStr.split(",")[1];
if (pre.endsWith("/")) {
if (after.startsWith("/")) {
return pre + after.slice(1);
} else {
return after + pre;
}
} else {
if (after.startsWith("/")) {
return pre + after;
} else {
return pre + "/" + after;
}
}
}
console.log(solution("/abc/,/bcd"));
//in: /acm,/bb /abc/,/bcd
//out: /acm/bb /abc/bcd