“9999 22 1234000 11 11 123 10003 44444444 2000”

    1. 跟举字符串的每个值的权重正序排序
      权重: 每个字符串相加的值
      例如: 9999 权重是36,1234000权重是10,就是每个字符串自身的值相加
    2. 复杂+
      当两个字符串权重相同的时候,按照他们数值大小排序 例如: 2000 10003 22
    1. function orderWeight(str) {
    2. let sum = (str) => str.split("").reduce((a, b) => a + +b, 0);
    3. let comp = (a, b) =>
    4. sum(a) == sum(b) ? a.localeCompare(b) : sum(a) - sum(b);
    5. return str.split(" ").sort(comp).join(" ");
    6. }
    7. orderWeight("9999 22 1234000 11 11 123 10003 44444444 2000"); // '11 11 2000 10003 22 123 1234000 44444444 9999'
    8. console.log(orderWeight("9999 22 1234000 11 11 123 10003 44444444 2000"));