javascript - 从给定的数字返回最大可能的数字?javascript
问题描述
如何从给定的数字中找到最大的数字?
例如:
const myFunction = input => {
return //im not sure how to produce what i need here.
}
myFunction(36);
//Should return 63
解决方案
那是你想要的吗?
function getMax(number) {
return parseInt(number.toString().split('').sort(function(a, b) { return b - a }).join(''));
}
console.log(getMax(36), getMax(128945));
推荐阅读
- android - ionic中的Android构建错误-包括Cordova插件文件
- c# - 重试失败的任务列表
- android - kotlinx.serialization 使用自定义序列化程序将 Int 转换为 Boolean
- excel - 在excel中使用宏提取英语词典单词
- r - R中的插值和外插
- c# - Azure Functions v1 中的 HTTP 触发器如何返回异步堆栈跟踪?
- php - 使用 php 查询 mySQL 数据库。如何将 WHERE 设置为 php var
- bash - 使用参数扩展设置默认变量 vs if/else test -z
- java - 如何将 Procyon 反编译器与 Diffoscope 一起使用
- python - 从源代码构建 Python 为 64 位