Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why can't codewars accept my answer? Im trying to practice in codewars using javascript

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 the problem:

Here’s my solution:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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));
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading