JSFiddle - React, Tailwind, and code Playground

by Michel Plungjan

JavaScript

function magicUrlCombine(a,b) {
  var linkA = document.createElement('a');
  linkA.href = a;
  var linkB = document.createElement('a');
  linkB.href = b;
    alert(linkA.href+"\n"+linkB.href+"\n"+linkB.href.replace(linkB.host,linkA.host))
  return linkB.href.replace(linkB.host,linkA.host)
}
function assert(statement) {
  return alert(eval(statement))
}
var a = 'http://example.com/some/path/';
var b = '../other/path/';
var c = magicUrlCombine(a,b);
assert(c == 'http://example.com/some/other/path/');
a = 'http://example.com/some/path/';
b = 'http://pink-unicorns.com/some/other/path/';
c = magicUrlCombine(a,b);
assert(c == 'http://pink-unicorns.com/some/other/path/');