I am a newbie and Im trying to practice codes with codewars. The problem is I already solve the problem, but it wont accept my codes.
Here’s my solution:
function descendingOrder(n){
var result =(n.toString().split('').reverse().sort(function(a, b){return b-a}).join(''));
parseFloat(result);
return result;
}
console.log(descendingOrder(12345));
What I tried is of course removing the parameter in function which is 12345 since codewars has already done it.
Kindly need your advice. Thanks in advance!!
>Solution :
You have some unnecessary functionality (like reverse()) in your code. In addition I understood you’re dealing with integers, not floats:
const descendingOrder = (n) => {
const result = n.toString().split('').sort((a, b) => b - a).join('');
return parseInt(result);
};
console.log(descendingOrder(123454821));