首页 > 解决方案 > 从给定的数字返回最大可能的数字?javascript

问题描述

如何从给定的数字中找到最大的数字?

例如:

const myFunction = input => {
  return //im not sure how to produce what i need here.
}

myFunction(36);
//Should return 63

标签: javascript

解决方案


那是你想要的吗?

function getMax(number) {
  return parseInt(number.toString().split('').sort(function(a, b) { return b - a }).join(''));
}
console.log(getMax(36), getMax(128945));


推荐阅读