|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
×
Write a function that rearranges an integer into its largest possible value.
- superSize(123456); // 654321
- superSize(105); // 510
- superSize(12); // 21
复制代码
If the argument passed through is single digit or is already the maximum possible integer, your function should simply return it.
- function superSize(num){
- var a = num.toString().split("");
- a.sort(function(x, y) {if (parseInt(x) > parseInt(y)) {return 1;} return -1;});
- a.reverse()
- return parseInt(a.join(""))
- }
复制代码 |
|