📜  js以降序反转int - Javascript代码示例

📅  最后修改于: 2022-03-11 15:04:07.799000             🧑  作者: Mango

代码示例2
//Method 2
//rearrange the digits to create the highest possible number
function descendingOrder(n){
  let reversed = n.toString().split("").sort((a, b) => b - a).join('');
  return parseInt(reversed) * Math.sign(n);
}
console.log(descendingOrder(463));        // result:  643
console.log(descendingOrder(223744));    // result:  744322