#20 - Sort Numbers CodeWars Kata (7 Kyu) - DEV Community
Maybe your like
Instructions
Finish the solution so that it sorts the passed in array of numbers. If the function passes in an empty array or null/nil value then it should return an empty array.
For example:
solution([1, 2, 10, 50, 5]); // should return [1,2,5,10,50] solution(null); // should return []
My solution:
function solution(nums){ return nums !== null ? nums.sort((a,b)=> a-b) : [] } Enter fullscreen mode Exit fullscreen modeExplanation
I returned a value using a conditional, if the nums array isn't null it will sort the nums array using a comparison function, it will rest a-b so it returns the nums array sorted correctly and if the element is null it will return an empty array
Did you like this solution? 👇🤔
My Github My twitter Solve this Kata
Templates let you quickly answer FAQs or store snippets for re-use.
Submit Preview Dismiss Code of Conduct • Report abuseAre you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
Cesar Del rio Follow Join me on my road to mastering coding. 100 days of codewars challenge. - Location México
- Work CEO at Mercurio Agencia Digital
- Joined Dec 29, 2021
We're a place where coders share, stay up-to-date and grow their careers.
Log in Create accountTag » Codewars-7 Kyu Solutions Python
-
CodeWars-7-kata - GitHub
-
Solutions For Codewars Problems Using Python 2.7 - GitHub
-
Solutions To Codewars Kata: 7 Kyu - Pythonatrix
-
GitHub - GitHub
-
Codewars-javascript · GitHub Topics
-
Training On MakeBackronym | Codewar Solution | 7 Kyu - YouTube
-
7 Kyu - Codewars
-
Codewars · GitHub Topics
-
Codewars-solutions Github
-
Is Codewars For Beginners? - Quora
-
How To Solve A 1 Kyu Kata On Codewars (or Any Difficult ... - Medium
-
Sans Titre
-
Yeah You Need To Be At Least Within 1 Rank To Unlock Solutions - Gitter
-
Codewars - 7 Kyu - Get The Middle Character - Replit