#20 - Sort Numbers CodeWars Kata (7 Kyu) - DEV Community

Add reaction Like Unicorn Exploding Head Raised Hands Fire Jump to Comments Save Boost More... Copy link Copy link Copied to Clipboard Share to X Share to LinkedIn Share to Facebook Share to Mastodon Share Post via... Report Abuse 1 #1 - Points of reflection (8 kyu) Codewars Kata 2 #2 - Hamming Distance CodeWars Kata (6 kyu) ... 43 more parts... 3 #3 - Wilson primes CodeWars Kata (8 kyu) 4 #4 - Pair of gloves CodeWars Kata (6 kyu) 5 #5 - People in the Bus CodeWars Kata (6 kyu) 6 #6 - Incrementer CodeWars Kata (7 kyu) 7 #7 - Closest and Smallest CodeWars Kata (5 kyu) 8 #8 - Simple remove duplicates CodeWars Kata (7 kyu) 9 #9 - Twin Prime CodeWars Kata (6 kyu) 10 #10 - Valid Spacing CodeWars Kata (7 kyu) 11 #11 - Vowel remover CodeWars Kata (8 kyu) 12 #12 - Fibonacci digit sequence CodeWars Kata (6 kyu) 13 #13 - Keypad Horror CodeWars Kata (7 kyu) 14 #14 - Keypad Horror CodeWars Kata (7 kyu) 15 #15 - Digits explosion CodeWars Kata (7 kyu) 16 #16 - Sums of parts CodeWars Kata (6 kyu) 17 #17 - The highest profit wins! CodeWars Kata (7 kyu) 18 #18 - Previous multiple of three CodeWars Kata (7 kyu) 19 #19 - Binary Addition CodeWars Kata (7 kyu) 20 #20 - Sort Numbers CodeWars Kata (7 kyu) 21 #21 - Sum of integers in string CodeWars Kata (7 kyu) 22 #22 - Find the unique number CodeWars Kata (6 kyu) 23 #23 - Change it up CodeWars Kata (6 kyu) 24 #24 - Create Phone Number CodeWars Kata (6 kyu) 25 #25 - Remove consecutive duplicate words CodeWars Kata (7 kyu) 26 #26 - Pillars CodeWars Kata (8 kyu) 27 #27 - Your order, please CodeWars Kata (6 kyu) 28 #28 - Sum of two lowest positive integers - CodeWars Kata (7 kyu) 29 #29 - Ones' Complement CodeWars Kata (7 kyu) 30 #30 - Multiplication table CodeWars Kata (6 kyu) 31 #31 - Sequences and Series CodeWars Kata (6 kyu) 32 #32 - Find the divisors! CodeWars Kata (7 kyu) 33 #33 -Derivatives of type x^n - CodeWars Kata (6 kyu) 34 #34 -Shortest code: Bug in Apple - CodeWars Kata (6 kyu) 35 #35 -(Ready for) Prime Time - CodeWars Kata (5 kyu) 36 #36 - Sum of Multiples CodeWars Kata (8 kyu) 37 #37 - Row of the odd triangle - CodeWars Kata (6 kyu) 38 #38 - Assemble string CodeWars Kata (6 kyu) 39 #39 - Two Sum CodeWars Kata (6 kyu) 40 #40 - Credit Card Mask Kata (7 kyu) 41 #41 - Split Strings Codewars Kata (6 kyu) 42 #42 - How many pages in a book? - Codewars Kata (6 kyu) 43 #43 - If you can read this... - Codewars Kata (6 kyu) 44 How can you help? 45 #44 - Where is my parent!?(cry) - Codewars Kata (6 kyu) 46 #45 - Persistent Bugger - Codewars Kata (6 kyu) 47 #46 - Sum of a sequence - Codewars Kata (7 kyu)

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 mode

Explanation

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

pic Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Submit Preview Dismiss Code of Conduct Report abuse

Are 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
#46 - Sum of a sequence - Codewars Kata (7 kyu) #javascript #programming #100daysofcode #computerscience Any advice for Google STEP program? #beginners #programming #javascript #motivation #45 - Persistent Bugger - Codewars Kata (6 kyu) #javascript #programming #100daysofcode #computerscience
DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

Tag » Codewars-7 Kyu Solutions Python