7 kyu

Sort Numbers

25,765 of 63,461jhoffner

Description:

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(c(1, 2, 3, 10, 5)) # should return c(1, 2, 3, 5, 10)
solution(NULL)              # should return NULL
solution([1, 2, 10, 50, 5]); // should return [1,2,5,10,50]
solution(null); // should return []
solution([1, 2, 10, 50, 5]); // should return [1,2,5,10,50]
solution(null); // should return []
solution([1, 2, 10, 50, 5]); // should return [1, 2, 5, 10, 50]
solution([]); // should return []
solution([1, 2, 10, 50, 5]) # should return [1,2,5,10,50]
solution(null) # should return []
solution([1, 2, 10, 50, 5]) # should return [1,2,5,10,50]
solution(nil) # should return []
solution([1,2,3,10,5]) # should return [1,2,3,5,10]
solution(None) # should return []
solution([1, 2, 10, 50, 5]) # should return [1,2,5,10,50]
solution(nothing) # should return []
SortNumbers(new int[] { 1, 2, 10, 50, 5 }); // should return new int[] { 1, 2, 5, 10, 50 }
SortNumbers(null); // should return new int[] { }
sort_numbers(&vec![1, 2, 3, 10, 5]); // should return vec![1, 2, 3, 5, 10]
sort_numbers(&vec![]); // should return !vec[]
sortNumbers [1, 2, 10, 50, 5] = Just [1, 2, 5, 10, 50]
sortNumbers [] = Nothing
# (Note in Lambda Calculus we have lists instead of arrays.)
nums = cons 1 (cons 2 (cons 10 (cons 50 (cons 5 nil))))
sort nums # cons 1 (cons 2 (cons 5 (cons 10 (cons 50 nil))))
sortNumbers({1, 2, 10, 50, 5}) // sholud return {1, 2, 5, 10, 50}
sortNumbers({}) // should return {}
int array[5] = {1, 2, 10, 50, 5};
sort_ascending(5, array); // array is now {1, 2, 5, 10, 50}
sort_ascending(0, NULL); // nothing to do for empty array
      SortNumbers([1, 2, 10, 50, 5])
      *  -> res = [1, 2, 5, 10, 50]
      SortNumbers([])
      *  -> res = []
sol(List(0, 3, 2, 5, 4, 1)) // returns List(0, 1, 2, 3, 4, 5)
sol(List()) // returns List()
solution([1, 2, 10, 50, 5]) # should return [1,2,5,10,50]
solution(nil) # should return [] of Int32
Fundamentals

Similar Kata:

Stats:

CreatedApr 22, 2013
PublishedApr 22, 2013
Warriors Trained85033
Total Skips5720
Total Code Submissions174956
Total Times Completed63461
JavaScript Completions25765
CoffeeScript Completions443
Ruby Completions4134
Python Completions19822
C# Completions2725
Rust Completions1459
Haskell Completions408
TypeScript Completions2037
R Completions526
C++ Completions3407
Clojure Completions265
Julia Completions63
PHP Completions1325
Go Completions2054
COBOL Completions14
C Completions616
λ Calculus Completions12
Scala Completions110
Crystal Completions8
Total Stars377
% of votes with a positive feedback rating89% of 4422
Total "Very Satisfied" Votes3610
Total "Somewhat Satisfied" Votes661
Total "Not Satisfied" Votes151
Ad
Contributors
  • jhoffner Avatar
  • glebec Avatar
  • El Corto Avatar
  • imjasonmiller Avatar
  • kazk Avatar
  • user5036852 Avatar
  • JohanWiltink Avatar
  • a.merezhanyi Avatar
  • Voile Avatar
  • Souzooka Avatar
  • KenKamau Avatar
  • rsa Avatar
  • hobovsky Avatar
  • khlivnyuk Avatar
  • trashy_incel Avatar
  • user8436785 Avatar
  • nmburaleh Avatar
  • ejini战神 Avatar
  • kvbc Avatar
  • akar-0 Avatar
  • zakro Avatar
  • dfhwze Avatar
  • KayleighWasTaken Avatar
  • AmirTallap Avatar
Ad