题解 | #字符统计#
字符统计
http://www.nowcoder.com/practice/c1f9561de1e240099bdb904765da9ad0
const str = readline(); var strarr = str.split(""); var strobj = {}; var newarr = []; strarr.forEach((item) => { if (strobj[item]) { strobj[item]++; } else { strobj[item] = 1; newarr.push(item); } }); for (var i = 0; i < newarr.length - 1; i++) { for (var j = i + 1; j < newarr.length; j++) { var char_1 = newarr[i]; var char_2 = newarr[j]; if (strobj[char_1] < strobj[char_2]) { var temp = newarr[i]; newarr[i] = newarr[j]; newarr[j] = temp; } else if (strobj[char_1] == strobj[char_2]) { if (char_1.charCodeAt() > char_2.charCodeAt()) { var temp = newarr[i]; newarr[i] = newarr[j]; newarr[j] = temp; } } } } console.log(newarr.join(""))