<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<p id="box"></p>
<script>
function compare(str, str1) {
var strone = str;
var strtwo = str1;
var obj1 = {};
var obj2 = {};
var rarr = [];
var rarr2 =[];
for(var x=0;x<strone.length;x++){
var chart = strone.charAt(x);
if(obj1[chart]){
obj1[chart]++;
}else{
obj1[chart]=1;
}
}
for (var k in obj1) {
if (obj1[k] === 1) {
rarr.push(k);
}
}
for (var y = 0; y < strtwo.length; y++) {
var chart2 = strtwo.charAt(y);
if (obj2[chart2]) {
obj2[chart2]++;
} else {
obj2[chart2] = 1;
}
}
for (var l in obj2) {
if (obj2[l] === 1) {
rarr2.push(l);
}
}
strone = rarr.join("");
strtwo = rarr2.join("");
for(var i = 0;i<strone.length;i++){
for(var j=0;j<strtwo.length;j++){
if(strone.charAt(i) === strtwo.charAt(j)){
var strr1 = strone.split(`${strone.charAt(i)}`).join('');
var strr2 = strtwo.split(`${strtwo.charAt(j)}`).join('');
}
}
}
var arrNovel = [];
arrNovel.push(strr1);
arrNovel.push(strr2);
var result = arrNovel.join("");
var zsort = result.split("").sort();
var fsort = [];
for(var i= zsort.length-1;i>=0;i--){
fsort.push(zsort[i]);
};
var lastResult = zsort.concat(fsort).join("");
return lastResult;
}
window.onload = function () {
document.getElementById('box').innerHTML = compare("aaaas1234dasdadassfaf5f4a6f4a684a6dAf", "wqefasf84fs4fsdrd");
}
</script>
</body>
</html>