解法:
const str = "xyxyXX";
const str1 = "abababb";
function solution(str) {const strArr = str.split("").sort((a, b) => a - b);const map = new Map();for (let i = 0; i < strArr.length; i++) {if (map.has(strArr[i])) {map.set(strArr[i], map.get(strArr[i]) + 1);} else {map.set(strArr[i], 1);}}let arr = [];for (let [key, value] of map) {arr.push(`${key}:${value}`);}return arr.sort((a, b) => b.split(":")[1] - a.split(":")[1]).join(";");
}console.log(solution(str1));
/*
xyxyXX => x:2;y:2;X:2
abababb => b4;a:3*/